The U.S. Supreme Court ruled on Monday that police officers may use evidence seized during a traffic stop even if the reason the officers pulled the car over was based on a misunderstanding of the state's law.

In the 8-1 decision, the Supreme Court ruled in favor of a North Carolina police officer who had stopped a car with a broken brake light – and then found cocaine in the car- even though driving with a faulty brake light isn’t against the law in the state.

Nicholas Heien argued that the sandwich bag of cocaine found in his car during the 2009 search should not have been allows as evidence because the police officer who stopped him had no valid reason to do so.

Heien, who consented to the search of the car after he was stopped, pleaded guilty and was given a maximum prison term of two years.

A state appeals court said the stop was impermissible because a quirky state law only requires a car to have one functioning brake light. But the state's highest court reversed, finding that the officer's mistaken reading of the law was reasonable.

The Supreme Court agreed, finding that the Fourth Amendment requires police to act reasonably, but not perfectly. Chief Justice John Roberts said that just as a police officer's mistake of fact can justify a traffic stop, a reasonable misunderstanding about the law can also satisfy the Constitution.

The ruling means Heien can't try to overturn his conviction for drug trafficking by suppressing the drug evidence found in his car.

Heien had argued that ignorance of the law is no excuse for citizens accused of crimes and said there shouldn't be a double standard for police. But Roberts said that simply means the state can't impose a punishment for something that isn't illegal.

"Heien is not appealing a brake-light ticket," Roberts said. "He is appealing a cocaine-trafficking conviction as to which there is no asserted mistake of fact or law."

Heien was a passenger when his car was pulled over on a North Carolina highway in 2009 because the right brake light was out. Officer Matt Darisse of the Surry County Sheriff's Department issued a warning citation over the light to the driver, Maynor Javier Vasquez.

Darisse then asked for permission to search the inside of the car and Heiein consented. The search revealed a plastic sandwich bag of cocaine in the trunk.

Roberts said the officer's decision to stop the car in the first place was reasonable given the confusing way in which the law was worded. Under North Carolina's decades-old law, all cars made after 1955 are required to have a "stop lamp" that can be part of "one or more other rear lamps." But no court had ever interpreted the law in the modern era to require only one working brake light.

"I suspect most of you here were surprised to learn that only one brake light is required in North Carolina, even if you are from North Carolina," Roberts said Monday as he read his opinion from the bench.

Both the state and the Obama administration had argued that refusing to allow such stops would inject too much uncertainty into the daily actions of police in the field who need to make quick decisions. Reasonable mistakes of law are acceptable, they argued, especially when dealing with a complex law that might be subject to different interpretations.

Justice Sonia Sotomayor was the lone dissenter. She said an officer's mistake of law "no matter how reasonable, cannot support the individualized suspicion necessary to justify a seizure under the Fourth Amendment."

The notion that the law "is definite and knowable sits at the foundation of our legal system," Sotomayor said. "And it is courts, not officers, that are in the best position to interpret the laws."

The Associated Press contributed to this report.