The $85bn (£63.5bn) deal, first announced in October 2016, was opposed by US president Donald Trump and the Justice Department over competition fears.
But Judge Richard Leon of the US District Court for the District of Columbia said the government had “failed to meet its burden to establish that the proposed transaction is likely to lessen competition substantially“.
The Justice Department had argued that AT&T’s ownership of both DirecTV and Time Warner, especially its Turner subsidiary, would give AT&T unfair leverage against rival pay TV providers that relied on content like CNN and Game Of Thrones.
As part of the deal approved by the judge, AT&T agreed to temporarily manage Time Warner’s Turner networks separately from DirecTV, including price setting.
Time Warner owns HBO, Turner and Warner Bros, and AT&T confirmed the acquisition overnight.
AT&T said it needed Time Warner to compete with the likes of Amazon, Netflix and Google, and that the deal would improve technology and give consumers more choices.
There is still the possibility of an appeal by the Justice Department, but experts have said overturning the judge’s decision could be an uphill battle.
Michael Carrier, who teaches law at Rutgers University, said: “I don’t think this would be overturned.
“It is so rooted in the facts that I would be surprised if an appellate court overturned such a fact-laden opinion.”
The merger, including debt, is the fourth largest deal ever attempted in the global telecom, media and entertainment sector, according to Thomson Reuters data.
It is also the 12th largest deal in any sector and has been watched closely by other companies pursuing similar tie-ups.
Among these is Comcast Corp, which made a $65bn bid on Wednesday for the entertainment assets of Twenty-First Century Fox Inc on Thursday.
Comcast, the largest US cable supplier, had been waiting for the AT&T decision before making any large moves, according to sources.
That agreement also covers the intended purchase of the 39.1% stake in Sky, the owner of Sky News, that Fox currently owns.