WASHINGTON—A long-running congressional battle over privacy and surveillance ended Tuesday when the Senate voted to curb the collection of millions of Americans’ phone records, the first significant retrenchment of government spying powers since the 9/11 attacks.

The measure, which was signed Tuesday night by President Barack Obama, will reauthorize and reboot the provisions of the USA Patriot Act that lapsed Sunday at midnight, but it will phase out the National Security Agency’s bulk phone-records program.

The bill, passed by the Senate Tuesday in a 67-32 vote, will shift storage of the phone records to telecommunications companies over six months.

Supporters said the legislation marked a victory for civil liberties diminished by laws put in place in the wake of the September 2001 terror attacks.

“Today the American people are now safe from the federal government’s collection of their personal data,” said Sen. Mike Lee of Utah, the bill’s chief GOP proponent in the Senate.