Acting with minutes to spare, President Obama approved a four-year extension of expiring provisions of the Patriot Act, after Congress overcame mounting opposition from both parties to narrowly avoid a lapse in the terrorist surveillance law.
Obama, attending an international summit in France, awoke early Friday to review and approve the bill, directing that it be signed in Washington by automatic pen before the provisions expired at midnight Thursday Eastern time.
The administration had warned Congress that any interruption in the surveillance authority would threaten national security.
Passage came late Thursday after a protracted political struggle that played out over several months, a sign of increased unease with powers granted to the federal government to investigate citizens and foreigners in the aftermath of the terrorist attacks of Sept. 11, 2001.
Dramatizing the debate this week, Sen. Rand Paul (R-Ky.) held up Senate floor proceedings to protest what he characterized as an unconstitutional overreach by the federal government into private affairs.
Earlier this year, unexpected opposition from a block of House Republicans thwarted a short-term extension of the retiring provisions, temporarily derailing the bill in that chamber.
Democrats similarly have opposed the post-Sept. 11 government authority, and this week's standoff risked an expiration of the provisions at midnight.
"We all want security — nobody wants what happened on 9/11 to happen again," Paul said. "But I think we don't need to simplify the debate to such an extent that we simply say we have to give up our liberties."
Supporters said that extending the provisions would ensure no disruption in the government's ability to conduct surveillance that they say has proved crucial to the ability of intelligence agencies to amass information vital to keeping the country safe.
By extending the measures through June 1, 2015, lawmakers codified a compromise with Republican leaders who preferred a permanent extension.
"The Patriot Act has been plagued by myths and misinformation for 10 years," said Rep. F. James Sensenbrenner Jr. (R-Wis.). "If Congress fails to reauthorize these laws before they expire, America's national security and that of its citizens will be the most vulnerable in a decade."
When authorized by Obama, the White House may use an "autopen" to replicate his signature. Similar machines have been used by past presidents, other public officials and celebrities and business officials to replicate their signatures.
One of the sections of the Patriot Act extended by Congress is the "roving wiretap" power, which allows federal authorities to listen in on conversations of foreign suspects even when they change phones or locations.
Another section gives the government access to the personal records of terrorism suspects; it's often called the "library provision" because of the wide range of personal material that can be investigated.
A third section is known as the "lone wolf" provision because it gives the government the authority to investigate foreigners who have no known affiliation with terrorist groups.
All of these government powers require an order from secret federal courts.
Senate leaders reached an agreement that allowed two amendments from Paul that sought to rein in the authority to investigate gun records and financial transactions, but both failed to advance.
The House voted 250 to 153, with 31 Republicans and 122 Democrats opposed.
Earlier, the Senate approved the bill 72 to 23. Four Republicans — Paul and Sens. Dean Heller of Nevada, Mike Lee of Utah and Lisa Murkowski of Alaska — joined 18 Democrats and independent Sen. Bernie Sanders of Vermont in opposition.
Christi Parsons in the Washington bureau contributed to this report from Deauville, France.