“Today was a huge victory for this merger,” John Legere, the chief executive of T-Mobile, said in a statement on Tuesday.

Known for his exuberant and often pugnacious leadership style, Mr. Legere made use of the court decision to take aim at AT&T and Verizon, using a special sobriquet for each: “Look out, Dumb and Dumber and Big Cable — we are coming for you … and you haven’t seen anything yet!”

Marcelo Claure, the executive chairman of Sprint, said the court decision “validates our view that this merger is in the best interests of the U.S. economy and American consumers.”

Letitia James, the New York attorney general and a key plaintiff in the case, warned on Tuesday that the deal would harm consumers.

Ms. James, who has argued that the merger would cost subscribers at least $4.5 billion annually, called the ruling “a loss for every American who relies on their cellphone for work, to care for a family member and to communicate with friends.” She added that the deal was always about “massive corporate profits over all else.”

T-Mobile and Sprint have said they do not plan to raise prices for at least three years.

Ms. James left open the possibility of an appeal, adding that her office “will continue to fight the kind of consumer-harming megamergers.”

One potential snag remains: The California Public Utilities Commission, which governs telecommunications services in the state, has yet to sign off on the merger plan. Consumer groups in California have argued that T-Mobile’s pledge to deliver faster service at affordable prices is unrealistic.