CVS Health won court approval for its $68 billion takeover of Aetna, removing the final barrier to a deal that adds a major health insurance business to a nationwide network of pharmacies and prescription-drug benefit programs.

U.S. District Judge Richard Leon on Wednesday signed off on a settlement reached last year with antitrust enforcers at the Justice Department that cleared the way to create a healthcare giant. Opponents of the merger had argued the combination would harm competition.

Shares of CVS rose 3% in after-hours trading following the decision.

Leon had ordered the companies and the U.S. to defend the tie-up in court after the deal closed last year before he’d granted final approval. He alluded to that in his 22-page decision, saying if the law giving him oversight “is to mean anything, it surely must mean that no court should rubber-stamp a consent decree approving the merger of ‘one of the largest companies in the United States’ and ‘the nation’s third-largest health insurance company.’”

Leon, in Washington, heard two days of testimony in June and then final arguments in July.

Opponents of the deal, including the American Medical Association, “raised substantial concerns that warranted serious consideration” but failed to show that the settlement wasn’t in the public interest, the judge found.

“CVS’s and the government’s witnesses, when combined with the existing record, persuasively support why the markets at issue are not only very competitive today, but are likely to remain so post-merger,” he wrote.

That isn’t necessarily the landscape Patrice Harris, president of the AMA, sees.

“We know from history that when health insurance and pharmaceutical benefit management markets are ruled by only a few massive companies, patients pay a steep price,” Harris said in a statement after the ruling.

Referring to the “unprecedented judicial review” spurred by the opponents’ concerns, she said regulators “must vigilantly monitor the conduct of the merged firm to make sure that this colossal new entity does not hurt patients.”

The tie-up was also fought by the AIDS Healthcare Foundation and the public interest groups U.S. PIRG and Consumer Action.

CVS spent almost two years trying to finalize the Aetna deal, which could have been derailed if Leon had rejected the regulatory settlement, even though the merger was completed last year. The Justice Department had argued that its agreement with CVS resolved the government’s antitrust concerns.

The department said in a statement Wednesday that the settlement requiring the sale of Aetna’s prescription drug business was a “comprehensive remedy” to the problems the DOJ identified.

The companies announced their merger plans in December 2017, promising to create an integrated health-care company with pharmacy locations that could be hubs for medical services and could better manage patients. To win government approval, CVS agreed to sell Aetna’s Medicare prescription-drug business to WellCare Health Plans Inc. The government said the sale was necessary to preserve market competition.

A month after the October deal with regulators, CVS closed the merger. The move angered the judge, who said then that the companies and the Justice Department were treating him like “a rubber stamp.” He suggested he might want to change or reject the settlement after hearing from opponents. Leon repeatedly criticized the DOJ antitrust division during the process, at one point calling it “hostile” to U.S. courts.

Merger settlements negotiated between companies and the department require court approval. It’s routine for merging entities to close their deals before a judge signs off, because they’re routinely approved without changes. Leon took the unusual step of holding a hearing on the settlement to hear from objectors.

The AMA relied heavily on the testimony of University of Southern California professor Neeraj Sood, a healthcare economist, who testified in June that the no matter how strong WellCare became, there would remain significant competitive concerns in some markets.

While the concerns cited by Sood and other witnesses served to “shed a healthy light on this merger,” they didn’t “substantially undermine” the positions staked out by the companies and by the U.S., the judge found.

“CVS Health and Aetna have been one company since November 2018, and today’s action by the district court makes that 100% clear,” T.J. Crawford, a spokesman for CVS, of Woonsocket, Rhode Island, said in an emailed statement. “We remain focused on transforming the consumer health care experience in America.”

The case is U.S. v. CVS Health Corp., 18-cv-2340, U.S. District Court, District of Columbia (Washington).