The odor of marijuana in a car that police in Berkeley stopped for other reasons wasn’t enough to justify a full-blown search of the vehicle now that California has legalized possession of cannabis by adults, an appellate panel has ruled.

“Marijuana and alcohol now receive similar treatment under the law,” said the Appellate Division of Alameda County Superior Court in a ruling barring evidence of a loaded handgun that police found during the search. The ruling was issued in December and was published by the state courts this week as a precedent for future cases.

It is one of the first appellate decisions on the effect of Proposition 64, the November 2016 initiative that allowed adults over 21 to buy, possess and use marijuana. They can possess up to an ounce of marijuana and grow as many as six plants for personal use, but cannot smoke pot in public or drive while under the influence.

The court said police were on a “specialized DUI patrol” on University Avenue one night in September 2017 when they saw a car drive past them without a front license plate. They turned on their lights and siren, and the driver immediately pulled over to the curb and was cooperative, the court said.

An officer smelled marijuana and questioned the driver, Andre Shumake, who replied that he had “some bud” in the center console. Suspecting the drug was being transported illegally, the officer searched the car and found a closed plastic tube in the console that contained 1.14 grams of marijuana bud, or “dried flower,” the court said.

Believing there might be more marijuana in the car, the officers searched further and found no drugs, but discovered a loaded pistol under the driver’s seat.

Shumake had not been driving erratically, and passed a field sobriety test at the scene. Superior Court Judge Margaret Fujioka ruled that the search was legal and allowed prosecutors to use the gun as evidence of illegal weapons possession, but was overruled by the appellate panel.

“The possession of the cannabis flower in this case was lawful,” Presiding Judge Noel Wise said in the 3-0 ruling. She said it was properly enclosed in a container and was only a fraction of the one-ounce maximum allowed by Prop. 64.

Prosecutors argued that police still had grounds to search the car and would have found the gun. But Wise said the only evidence officers had was the strong smell of fresh and recently burnt marijuana and Shumake’s statement that he possessed a small amount of the drug, not enough to justify a search of a driver who was cooperating and showed no signs of impairment.

“Anyone 21 years and older can now lawfully smoke marijuana in California and, as (the officer) testified, the smell can linger for more than a week,” Wise said. “Given the legality of personal use of marijuana in the state of California, there was not a fair probability that (the officer) would find evidence of a crime” in a legal search.

Bob Egelko is a San Francisco Chronicle staff writer. Email: begelko@sfchronicle.com Twitter: @BobEgelko