WASHINGTON — In a major statement on privacy in the digital age, the Supreme Court ruled on Friday that the government generally needs a warrant to collect troves of location data about the customers of cellphone companies.

The 5-to-4 decision has implications for all kinds of personal information held by third parties, including email and text messages, internet searches, and bank and credit card records. But Chief Justice John G. Roberts Jr., writing for the majority, said the decision was limited.

“We hold only that a warrant is required in the rare case where the suspect has a legitimate privacy interest in records held by a third party,” the chief justice wrote. The court’s four more liberal justices joined his opinion.

The case, Carpenter v. United States, No. 16-402, arose from armed robberies of Radio Shacks and other stores in the Detroit area starting in 2010.

Witnesses said that Timothy Ivory Carpenter had planned the robberies, supplied guns and served as lookout, typically waiting in a stolen car across the street.

Tech companies weigh in

“At his signal, the robbers entered the store, brandished their guns, herded customers and employees to the back, and ordered the employees to fill the robbers’ bags with new smartphones,” a court decision said, summarizing the evidence against him.

Mr. Carpenter’s lawyers said cellphone companies had turned over 127 days of records that placed his phone at 12,898 locations, based on information from cellphone towers. The records disclosed whether he had slept at home on given nights and whether he attended his usual church on Sunday mornings.

Technology companies including Apple, Facebook and Google filed a brief urging the Supreme Court to continue to bring Fourth Amendment law into the modern era. “No constitutional doctrine should presume,” the brief said, “that consumers assume the risk of warrantless government surveillance simply by using technologies that are beneficial and increasingly integrated into modern life.”

Older Supreme Court decisions offered little protection for information about businesses’ customers. In 1979, for instance, in Smith v. Maryland, the Supreme Court ruled that a robbery suspect had no reasonable expectation that his right to privacy extended to the numbers dialed from his landline phone. The court reasoned that the suspect had voluntarily turned over that information to a third party: the phone company.

Relying on the Smith decision’s “third-party doctrine,” federal appeals courts have said that government investigators seeking data from cellphone companies showing users’ movements do not require a warrant.

A federal law, the Stored Communications Act, does require prosecutors to go to court to obtain tracking data, but the showing they must make under the law is not probable cause, the standard for a warrant. Instead, they must demonstrate only that there were “specific and articulable facts showing that there are reasonable grounds to believe” that the records sought “are relevant and material to an ongoing criminal investigation.”

The court’s decision in the case, Carpenter v. United States, No. 16-402, applied the Fourth Amendment, drafted in the 18th century, to a world in which people’s movements are continually recorded by devices in their pockets and cars, by toll plazas and by transit systems.