Aetna Inc. agreed to buy Humana Inc., the second-largest provider of private Medicare insurance, for $37 billion in cash and stock.

The transaction values Humana at $230 a share based on yesterday’s closing price for Aetna, the companies said in a statement Friday. That’s 23 percent above Humana’s last close.

The acquisition comes amid a period of consolidation in the industry, with all of the five biggest health insurers looking at deals. Humana’s 3.2 million Medicare Advantage members have made it a target, since more Americans are turning 65 and becoming eligible for the health program for the elderly and its private insurer-run version.

“Medicare Advantage is a coveted space,” Michael Bernstein, a partner at Baird Capital’s U.S. private equity team who focuses on health care, said in an interview before the transaction was announced. “To develop a similar scale in Medicare would take a great deal of work and time, which would be bypassed by making that transaction happen.”

Medicare membership is projected to rise to 68.4 million in 2023, up 26 percent from this year, according to the Centers for Medicare & Medicaid Services. Humana, based in Louisville, Kentucky, covers more than 14 million people through commercial, Medicare and Medicaid plans.

Centene Corp. said Thursday it agreed to buy Health Net Inc. for about $6.3 billion in a deal that creates the biggest private administrator of Medicaid, the federally funded health program for the poor. Cigna Corp. rejected a $47 billion takeover bid from Anthem Inc. last month, saying the offer wasn’t in the best interests of shareholders and Anthem executives weren’t fit to lead a merged insurance giant.

Some of the consolidation talk has been fueled by the Patient Protection and Affordable Care Act. Known as Obamacare, the 2010 law overhauled the U.S. health-care system with new rules that push insurers to look for savings. The law also provides subsidies to help people afford coverage, creating millions of new customers that the companies are racing to capture.

A Supreme Court ruling upholding those subsidies for more than 6 million people has helped clear the path to dealmaking. The 6-3 decision on June 25 in the King v. Burwell case said the U.S. can continue to give people money to help them buy coverage on the federal healthcare.gov website.