A U.S. federal judge blocked Aetna's proposed $34 billion merger with rival Humana, saying it was illegal under antitrust law. (Reuters)

This story has been updated.

A federal judge has prohibited the merger of two health insurance giants, Aetna and Humana, upholding the Justice Department's decision that the $37 billion deal would hurt competition and raise prices for consumers.

"The Court is unpersuaded that the efficiencies generated by the merger will be sufficient to mitigate the anticompetitive effects for consumers in the challenged markets," U.S. District Judge John D. Bates wrote in his 158-page opinion.

In July, the Justice Department sued to block the merger, arguing that it would reduce competition in the Medicare Advantage market and in some of the exchanges set up under the Affordable Care Act. Medicare Advantage plans are Medicare health plans offered by private insurers.

"We are reviewing the opinion now and giving serious consideration to an appeal, after putting forward a compelling case," Aetna spokesman T.J. Crawford said. The companies' merger agreement, which has already been extended twice, will expire Feb. 15.

Humana did not immediately respond to a request for comment.

Bates wrote in his opinion that the proposed merger would have decreased competition substantially in the Medicare Advantage market in 364 counties. Aetna and Humana had argued that Medicare Advantage plans also competed against traditional Medicare options, but the judge sided with the Justice Department that the private Medicare plans were a separate market. The companies also proposed that divesting some of that business to a smaller insurer, Molina Healthcare, could have addressed those concerns, but the judge did not agree.

The merger was also deemed to lessen competition in the exchanges set up by the ACA in three Florida counties. Aetna withdrew from the majority of the exchanges that it had participated in this year, citing financial losses. The judge, however, wrote that Aetna withdrew from 17 counties highlighted in the case "specifically to evade judicial scrutiny of the merger."

Deputy Assistant Attorney General Brent Snyder, current head of the Justice Department's Antitrust Division, said in a statement the decision a victory for consumers. He said taxpayers and customers would save up to a half-billion dollars each year.

"This merger would have stifled competition and led to higher prices and lower quality health insurance," Snyder said.

In a research note, Ana Gupte, an analyst at Leerink Partners wrote that she had expected the deal to have a one in three chance of closing. She added that other bidders could now emerge for Humana.

In a separate case, Anthem and Cigna are fighting the Justice Department's decision last summer to block its $54 billion merger. The decision in that case is still pending, but Gupte said she expects that deal will be blocked, as well.

Matthew Cantor, a partner at Constantine Cannon, an antitrust law firm, said that the decision was based on a thorough analysis by the judge and argued that an appeal likely would be difficult from a legal standpoint. But he noted that a wild card could be the role of the Trump administration, which is pressing to replace the ACA and will be negotiating with insurers who sell plans in the marketplaces and in whatever replaces them.

"You have a White House -- at least when they were in the president-elect phase -- that has seemingly been receptive to having discussions with executives whose mergers are under review," Cantor said. "It could be that the independence of the Justice Department is cast aside here, in order to create a settlement which would benefit, from a political standpoint, the Trump administration. If they, in fact, revise the ACA so drastically and they can get public statements from these insurers -- these large insurers -- that they support the transition."

Dan Mendelson, president of Avalere Health, said that he expects insurers to continue to make acquisitions or attempt mergers, whether on appeal or in new deals. He said it's possible that insurers could turn to acquiring data and analytics firms.

"Health plans have been and will continue to be acquisitive," Mendelson said. He pointed out that the largest health insurer, UnitedHealth Group, "has already scaled up to a very large degree, so the other companies are interested in following suit."

The stock prices of both companies fell on the news, although Humana's stock recovered and closed at a higher price. Aetna's share price closed down 2.7 percent, and Humana's stock closed up 2.2 percent.

The decision was applauded by advocates for doctors and patients.

"The court ruling halts Aetna’s bid to become the nation’s largest seller of Medicare Advantage plans and preserves the benefits of health insurer competition for a vulnerable population of seniors," Andrew Gurman, president of the American Medical Association, said in a statement.

Sen. Richard Blumenthal (D-Conn.) released a statement applauding the decision, as well.

“Today’s ruling is a decisive victory for jobs, consumers, and healthcare. Mega-mergers like the proposed consolidation of Aetna and Humana raise prices, lower health care quality – and kill jobs,” Blumenthal said.

More from Wonkblog:

Drugmakers question the future of drug prices under Trump