A federal judge has approved Sprint and T-Mobile’s $26 billion merger, creating the nation’s third-largest wireless carrier as the industry hurtles toward the new frontier of ultrafast 5G service.

T-Mobile and Sprint, ranked Nos. 3 and 4 by size, have argued for years that the deal would shield them from the industry’s brutal pricing wars and expedite their ability to deliver 5G to the masses. Last year, they promised Washington they would build out a 5G wireless network to 97% of the country in three years, including much of rural America, while offering “same or better rate plans at the same or better prices” for the next three years. The combined company is expected to serve more than 100 million subscribers, rivaling the even larger footprints of AT&T and Verizon.

Sprint shares spiked more than 72%, to $8.28, in premarket trading. T-Mobile surged 9.6%, to $92.65.

Richard Parker, legal counsel for T-Mobile’s parent company, Deutsche Telekom, said in a statement emailed to The Post that the company was “delighted” with the decision. “As we argued in court, this merger ensures competition by allowing the combined companies to more effectively compete with the market leaders. It is our hope that with the Court’s endorsement of the merger, along with the federal agencies’ approval, this matter can be closed so that the market can do what it does best: fuel competition and innovation.”

Sprint, run by Japanese conglomerate Softbank, did not respond to a request for comment.

Critics contend the deal will squash competition, leaving consumers with too few choices and allowing for price-gouging that could disproportionately affect lower-income customers. And while the Federal Communications Commission and the Justice Department approved the deal last year, a group of 13 state attorneys general, including California and New York, later sued to block it. But in his ruling Tuesday, U.S. District Court Judge Victor Marrero said that the merger was unlikely to “substantially lessen competition” in the telecom industry.

“T-Mobile has redefined itself over the past decade as a maverick that has spurred the two largest players in its industry to make numerous pro-consumer changes. The proposed merger would allow the merged company to continue T-Mobile’s undeniably successful business strategy for the foreseeable future,” Marrero wrote in his decision. “While Sprint has made valiant attempts to stay competitive in a rapidly developing and capital-intensive market, the overwhelming view both within Sprint and in the wider industry is that Sprint is falling father and farther short of the targets it must hit to remain relevant as a significant competitor.”

The deal still requires the endorsement of the California Public Utilities Commission, a move two years in the making, and it’s possible the legal battle isn’t over yet. New York Attorney General Letitia James, who spearheaded the lawsuit, said that the states “wholeheartedly” disagreed with Marrero’s ruling are considering an appeal.

“From the start, this merger has been about massive corporate profits over all else, and despite the companies’ false claims, this deal will endanger wireless subscribers where it hurts most: their wallets,” James said in a statement. “There is no doubt that reducing the mobile market from four to three will be bad for consumers, bad for workers, and bad for innovation, which is why the states stepped up and led this lawsuit.”

The merger was formally announced in April 2018, but T-Mobile and Sprint, run by Japanese conglomerate Softbank, had been flirting with a combination for years but were thwarted by political head winds. To win the government’s blessing, both companies agreed to sell off key assets – including hundreds of retail stores, thousands of cell sites and spectrum licenses – to Dish Network in an effort to turn Dish into a fourth national wireless carrier. Sprint and T-Mobile were also forced to ditch their prepaid phone businesses, Boost Mobile and Virgin Mobile.

Mike Siebert, T-Mobile’s current president, is poised to succeed John Legere as chief executive to helm the newly combined company on May 1. Legere, whose charisma and acumen helped move the merger forward, will remain a member of the board.

How the T-Mobile and Sprint merger would affect customers