German drug firm Bayer has won its fight to take over rival Schering after a company that was building a stake in the firm agreed to sell its shares.
Despite the conflict, Bayer hopes to work with Merck in the future
Bayer had launched a court case against Merck KGaA, accusing its German peer of buying Schering shares to block its 16.5bn euro ($20.3bn, £9bn) bid.
Schering had earlier rejected a bid from Merck, preferring Bayer's offer.
Merck will get 89 euros for every Schering share, which is more than Bayer had initially wanted to pay.
Bayer's shares climbed almost 7% to 32.68 euros after the announcement, and Merck jumped more than 6% to 72.64 euros. Shares of Schering added 1.8% to 89.01 euros.
"We're very pleased about Merck's decision, because a lengthy competitive bidding process would have greatly affected Schering's future," said Werner Wenning, Bayer's chief executive.
"All three companies concerned will benefit from this step," he explained, adding that following the deal Bayer hoped to now reach the 75% share-ownership threshold it needed for the takeover to go ahead.
Bayer will now withdraw its legal action that it had filed in the US District Court of Manhattan because about 19% of Schering's stock is held in the US.
Over recent days, Merck had built up a 22% holding in Schering, with most of the buying coming over the past few days.
Merck said it would make a profit of 400m euros from the share sale.
Based in the German state of Hesse, Merck no longer has any connection with the US pharmaceutical firm of the same name.
The US-based Merck was originally a subsidiary of the German company, but became independent after World War I.