WASHINGTON — The Supreme Court on Monday upheld a North Carolina car search, in an 8-1 decision that provides more wiggle room for law enforcement officers who make a “reasonable” mistake about the law.

With conservative and liberal justices all but united, the court ruled that the 2009 search was permissible even though the Surry County Sheriff’s Office sergeant who conducted it erred in thinking the car violated state law governing warning brake lights.

“To be reasonable is not to be perfect, and so the Fourth Amendment allows for some mistakes on the part of government officials, giving them fair leeway for enforcing the law in the community’s protection,” Chief Justice John Roberts Jr. wrote.

Justice Sonia Sotomayor was the sole dissenter, arguing that the decision means “further eroding the Fourth Amendment’s protection of civil liberties in a context where that protection has already been worn down.”

The Fourth Amendment prohibits unreasonable searches and seizures. The Supreme Court has previously ruled that a search might be permissible if the officer makes a reasonable factual mistake. Roberts cited the example Monday of an officer stopping a motorist for traveling alone in an HOV lane, only to discover that two children are slumped over asleep in the back seat.

The case decided Monday extended the same kind of reasoning to different kinds of mistakes, dealing with the law.

“Reasonable men make mistakes of law, too, and such mistakes are no less compatible with the concept of reasonable suspicion,” Roberts wrote.

Underscoring the case’s broader significance, 19 states filed a brief siding with North Carolina.

The case grew out of a police stop on the morning of April 29, 2009, when Sgt. Matt Darisse of Surry County pulled over a Ford Escort on Interstate 77 near Dobson, N.C., about 90 miles north of Charlotte. Darisse had begun following the car because he thought the driver looked “stiff and nervous.”

Darisse thought he had reason to pull the car over and subsequently search it when he noticed that only one of its brake lights went on while the car slowed. At the time, Darisse said he thought North Carolina law required that cars have two working brake lights; the North Carolina Court of Appeals later ruled Darisse was wrong.

The driver, who was not involved in the case decided Monday, and the car’s owner, Nicholas Brady Heien, did not object to a search. Following a search of about 40 minutes, Darisse found in the side compartment of a duffel bag a sandwich bag containing cocaine.

Heien pled guilty, while reserving the right to appeal.

“Only by refusing to excuse such mistakes can officers be properly deterred from engaging in such overly ambitious readings of the traffic code, at the expense of individual liberty,” Stanford Law School professor Jeffrey L. Fisher wrote in a brief filed on Heien’s behalf.

The court’s majority, though, reasoned that law enforcement officers sometimes must act quickly, even in cases where the law’s technical specifications may be hard to come by.

“A law prohibiting ‘vehicles’ in the park either covers Segways or not,” Robert noted as an example, “but an officer will nevertheless have to make a quick decision on the law the first time one whizzes by.”

Heien, now 26, was released from prison in 2012, state records show.