WASHINGTON — A federal judge reviewing a Justice Department decision to allow CVS Health to merge with the health insurer Aetna said on Wednesday that the agreement was in fact legal under antitrust law.

Judge Richard Leon of United States District Court in Washington had been examining a government plan, announced in October, to allow the merger on the condition that Aetna sell its Medicare prescription drug plan business to WellCare Health Plans. Both deals have already been closed.

Judge Leon had initially balked at approving the merger conditions and insisted on hearing from critics of the deal, but finally decided to grant the motion to approve the consent agreement. But he took aim at the common practice of companies’ closing multibillion-dollar deals while the court review, required by the Tunney Act, was still in progress.

“If the Tunney Act is to mean anything,” Judge Leon wrote, “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,’ simply because the government requests it!”