AT&T has scrapped its plans to purchase rival mobile carrier T-Mobile USA in the face of opposition from two U.S. agencies.

AT&T said Monday it has agreed to end its bid to acquire T-Mobile USA from parent company Deutsche Telekom for $39 billion. AT&T will "continue to invest" in its own services, Randall Stephenson, AT&T chairman and CEO, said in a statement.

Stephenson called on the U.S. Federal Communications Commission and Congress to move quickly to deal with looming spectrum shortages in the mobile industry. The FCC should "expeditiously" approve AT&T's deal to buy 700MHz spectrum from Qualcomm for $1.9 billion, and lawmakers should move ahead on plans to make new spectrum available for mobile broadband, he said.

AT&T had argued that the T-Mobile spectrum would help it handle skyrocketing demands for mobile broadband services.

"The mobile Internet is a dynamic industry that can be a critical driver in restoring American economic growth and job creation, but only if companies are allowed to react quickly to customer needs and market forces," Stephenson said in the statement.

AT&T will pay a $4 billion breakup fee to Deutsche Telekom, with the charge added to the company's fourth-quarter financial results. AT&T will also enter into a roaming agreement with the German carrier, the company said in a press release.

Both the FCC and the U.S. Department of Justice had opposed the deal. The DOJ filed an antitrust lawsuit to block it in August, and the FCC announced in November that its staff had found the acquisition to be contrary to the public interest.

Public Knowledge, a digital rights group that led the charge against the deal, applauded AT&T's decision.

"In this age of cynicism, it is important for the American people to see that Washington does not always go to the highest bidder," said Harold Feld, Public Knowledge's legal director. "The Department of Justice and the Federal Communications Commission stood up to tremendous lobbying pressure as AT&T spent tens of millions of dollars trying to push this merger through."

Feld said he hopes AT&T and T-Mobile will now focus on deploying their networks, "rather than trying to merge to duopoly," with AT&T and Verizon controlling nearly 80% of the U.S. mobile market if the merger had happened.

"These businesses are fundamentally sound, and have what it takes to bring broadband and jobs to America on their own," he added.

After the FCC's November announcement, AT&T withdrew its application at the FCC to transfer T-Mobile's spectrum licenses. The deal appeared to be doomed earlier this month when Judge Ellen Segal Huvelle, overseeing the DOJ case at the U.S. District Court for the District of Columbia, grilled AT&T's lawyers about how they expected to move forward with the acquisition without an active license transfer application at the FCC.

A week ago, AT&T and the DOJ filed a joint motion to put the antitrust case on hold while AT&T considered its options. Huvelle quickly approved the motion.

After the hearing before Huvelle earlier this month, many mobile analysts said they didn't see how AT&T could restructure the deal and win approval in the court case and before the FCC.

AT&T refused to give up on the deal long after many other observers did, said Jeff Kagan, an independent telecom analyst.

"I thought it was done when the DOJ weighed in. It wasn't," he said. "I thought it was done when the FCC weighed in. It wasn't."

AT&T could possibly propose the deal in a few years, when the antitrust climate in Washington has changed, Kagan said. T-Mobile could also talk to smaller mobile carriers about merging, he added.