AT&T said Sunday it has agreed to purchase T-Mobile USA in a $39 billion acquisition that greatly consolidates the wireless industry and tests federal regulators, who will scrutinize whether the deal harms competitors.

The union would create the largest cellular phone carrier in the country and comes as consumers increasingly flock to smartphones and tablets to access the Internet.

Some federal lawmakers immediately expressed concern that the merger would dampen competition and lead to fewer options and higher prices for mobile services.

The merger was a surprise, as Wall Street speculated in recent weeks that Deutsche Telekom would sell its T-Mobile USA unit to Sprint Nextel. Those two companies are struggling to retain subscribers as giants AT&T and Verizon Wireless pick up customers attracted to exclusive partnerships to carry Apple’s iPhone and Motorola’s Droid.

AT&T announced Sunday that its board and that of Deutsche Telekom had approved the deal, which includes $25 billion in cash and the rest in AT&T stock.

The agreement highlights a fierce race to gain subscribers as network operators deploy new high-speed 4G Internet service , which can bring better and faster — and more expensive — connections.

“This transaction represents a major commitment to strengthen and expand critical infrastructure of our nation’s future,” AT&T CEO Randall Stephenson said in a release.

He said the merged company would bring wireless access to more rural and underserved areas sooner than the separate companies would.

Specifically, AT&T promised to provide 4G wireless services to 95 percent of the population by building more cell towers across the country. That’s 46.5 million more consumers than the company originally planned to provide with 4G.

The combined company would have about 130 million users, the most of any U.S. wireless provider. Economists and policymakers have been looking to mobile Internet services as a driver of future growth.

The deal will be closely scrutinized by federal regulators because a merger would have consequences for many consumers.

Key lawmakers, including Sen. Herb Kohl (D-Wis.), head of the Senate Judiciary antitrust subcommittee, said in a statement that the group would closely scrutinize the deal for implications on consumer wireless prices and quality of service.

Consumer advocacy groups immediately decried the merger. They pointed to consistently higher mobile phone bills each successive year. Carriers are also switching billing to tiered data plans that consumer groups fear will lead to higher costs.

“The wireless market, now dominated by four big companies, would have only three at top,” said Gigi Sohn, president of public interest group Public Knowledge. “We know the results of arrangements like this — higher prices, fewer choices, less innovation.”

T-Mobile has offered some of the lowest service prices in recent years.

The deal would have to be approved by antitrust regulators at the Justice Department and the Federal Communications Commission, which oversees the transfer of wireless licenses.

The FCC earlier this year approved the mega-merger of media companies Comcast and NBC Universal after imposing a number of public interest conditions.

The deal between AT&T and T-Mobile could be viewed as a way to expedite the FCC’s goal to bring mobile and other broadband connections to all Americans.

“We knew there would be some kind of merger, and this is better than others because it could get more wireless connections to rural areas,” said Larry Cohen, president of the Communications Workers of America labor union.

T-Mobile USA is based in Bellevue, Wash., and is part of T-Mobile International, which will remain in the hands of Deutsche Telekom. If the deal is completed, Deutsche Telekom will own 8 percent of ATT’s stock.

Analysts said the merger would benefit AT&T because it also removes a low-priced competitor. “Even if it doesn’t go through, AT&T will have hobbled T-Mobile’s ability to do another deal or acquire more spectrum through what will be a long review process,” said Rebecca Arbogast, head of technology policy research at Stifel Nicolaus.