Express Scripts said Thursday that it would buy a smaller rival, Medco Health Solutions, for $29.1 billion, becoming the biggest pharmacy benefits manager in the country in one of the largest deals of the year.

Under the terms of the deal, Express Scripts will pay $28.80 in cash and 0.81 of an Express Scripts share for each Medco share. On Thursday morning, the deal valued Medco at $71.36 a share, 28 percent above its closing price on Wednesday.

After the deal closes, Express Scripts will own 59 percent of the combined company. George Paz, the chairman and chief executive of Express Scripts, will continue to hold those titles. The board of the new company will be expanded to include two of Medco’s independent directors.

The merger is a sign of the times for the health care industry, which has experienced significant consolidation as it adjusts to the coming overhaul in health insurance.

Deutsche Bank analysts called the deal a “highly unexpected marriage of two fierce competitors” that highlighted how much the industry was changing. The analysts, led by Ross Muken, wrote that the transaction “should also help to quell some fears over the sustainability of long-term profit growth.”

Companies like Express Scripts and Medco help employers, health plans, labor unions and government agencies fulfill benefits for prescription drugs and reduce the cost of treatments by negotiating discounts from drug makers. They often run mail-order pharmacies as well.

“The cost and quality of health care is a great concern to all Americans,” Mr. Paz said. “This is the right deal at the right time for the right reasons.”

In Medco, Express Scripts finally has its big drug benefits merger. The company unsuccessfully battled CVS for CareMark Rx four years ago, stymied in part by antitrust concerns. This time around, Express Scripts emphasized that despite buying Medco, it would still face competition from a variety of drug benefits managers.

“On the regulatory front, we expect a drawn-out process,” Steven Halper, an analyst at Stifel Nicolaus, wrote in the research note on Thursday. “Five years ago, Express was very confident that it would get regulatory approval for its attempted purchase of Caremark.”

Mr. Muken, of Deutsche Bank, agreed: “Under the Obama administration, the F.T.C. has been significantly more strict” in the deals it approves and rejects, he said.

“There’s going to be a pretty heavy lobby from the pharma community” against the deal, he said, because Express Scripts and Medco would be creating “an entity with a lot of power in the supply chain.”

Still, the Deutsche Bank analysts are predicting that the acquisition will be completed late in the first half of next year.

Medco, one of the largest pharmacy benefits manager in the country, said in May that it had lost the 2012 contract with the Federal Employees Health Benefits Program to CVS Caremark, a contract that accounted for about $3 billion in annual revenue. Last month it lost the account of the California Public Employees’ Retirement System to CVS as well. Medco’s stock is down 8.96 percent for the year.

Express Scripts said that it expected to realize about $1 billion in cost savings once the deal was completed, and that it would begin adding to earnings per share in the first full year after the deal closed.

The merger is subject to regulatory and shareholder approval.

Express Scripts was advised by Credit Suisse, Citigroup and the law firm Skadden, Arps, Slate, Meagher & Flom. Medco was advised by JPMorgan Chase, Lazard and the law firms Sullivan & Cromwell and Dechert.