Genentech had rejected an earlier offer from Roche
Drugs company Roche has agreed to merge with Genentech, and is to buy the remaining shares of the US firm for $46.8bn (£33.7bn).
Roche already owned 55% of Genentech. The deal ends a long struggle between the two companies and is the latest merger in the pharmaceutical sector.
The combined group will generate about $17bn in annual revenues and be the seventh-largest US drugs company.
Much of Genentech's revenue comes from cancer-related drugs.
Roche expects the merger to generate annual pre-tax cost savings of about $750m to $850m.
Roche offered $89 per share for the outstanding stock in July but Genentech shareholders rejected the offer as being too low. The new offer is for $95 a share.
"We believe this is a fair offer for Genentech shareholders, and the committee is pleased to come to a successful conclusion of this process," said Charles Sanders, chairman of the special committee of Genentech's board of directors.
Roche chairman Franz B. Humer said: "Working together, we aim to close the transaction quickly, thus removing uncertainty for employees and allowing us to focus even more intently on innovation and long-term projects."
Analysts at Julius Baer Group said: "A price below $100 per share has to be seen as positive [for Roche]."
Earlier this week, Merck announced that it was to buy rival Schering-Plough in a $41.1bn deal, creating one of the world's biggest pharmaceutical companies.
Large drug companies have been trying to diversify, as prices fall and the patents on blockbuster drugs come close to expiring.