President Barack Obama has signed legislation reviving and reshaping surveillance laws that expired temporarily Sunday night.

The White House says Obama signed the bill late Tuesday evening, hours after the Senate gave its final approval.

Obama said in a statement that he's gratified Congress finally approved the bill. He says his administration will move quickly to restore the lapsed surveillance tools.

The law eliminates the National Security Agency's bulk phone-records collection program and replaces it with a more restrictive measure to keep the records in phone companies' hands.

Obama had blamed Congress for needless delays and an “inexcusable lapse” in national security tools. But he also praised some senators and House members for working in bipartisan fashion to come up with a compromise.

Congress sent legislation to the president reviving and remaking a disputed post-9/11 surveillance program two days after letting it expire.

The vote in the Senate Tuesday was 67-32. The House already passed the bill.

The legislation will phase out, over six months, the once secret National Security Agency bulk phone record collection program made public two years ago by former agency contractor Edward Snowden.

It will be replaced by a program that keeps the records with phone companies but allows the government to search them with a warrant.

Senate Republican leaders initially opposed the House bill, arguing first for an extension of the Patriot Act, the sweeping surveillance legislation passed in the days immediately after the attacks of Sept. 11, 2001. But Senate Majority Leader Mitch McConnell, R-Ky., was eventually forced to accept the House version unchanged after senators rejected various last-ditch attempts to amend it.

The legislation would continue other post-9/11 surveillance provisions that also lapsed at 12:01 a.m. Monday. These include the FBI's authority to gather business records in terrorism and espionage investigations and to more easily eavesdrop on suspects who regularly discard cellphones to avoid surveillance.