Police need a warrant or an emergency to enter someone’s home, the California Supreme Court ruled Monday, discarding a 20-year-old opinion that would allow entry for less-urgent reasons.

One’s home is the place “where privacy expectations are most heightened,” the court said, quoting a 1986 U.S. Supreme Court ruling. Citing their own ruling in a 2005 case, the justices said police who lack a warrant can enter only when “swift action” is needed “to prevent imminent danger to life or serious damage to property, or to forestall the imminent escape of a suspect or destruction of evidence.”

The 7-0 ruling rejected a standard proposed in 1999 by three justices that would allow police to enter a private home for “community caretaking” to meet needs that fell short of an emergency — and using any evidence they noticed after entering.

Officers, for example, could cite “the possibility someone inside required assistance or property needed protection” to justify entering without a warrant, then-Justice Janice Rogers Brown wrote in the 1999 case, upholding a home search in Contra Costa County. Arguing for that standard in the current case, Attorney General Xavier Becerra’s office said “community care-taking” could include such needs as “assisting those who cannot care for themselves” or “returning lost children to anxious parents.”

Although Brown’s opinion lacked the majority support needed for a binding precedent, it has been followed by some lower courts in California, including the appellate court in the current case. That court allowed prosecutors to use evidence of guns and drugs that officers found in the home of a Santa Barbara man who was disarmed, searched and handcuffed outside before they entered the home.

The state’s high court ruled the evidence inadmissible and allowed the homeowner, Willie Ovieda, to withdraw his guilty plea to charges of manufacturing illegal drugs and possessing an assault weapon. He had been sentenced to probation.

The case illustrated the sometimes-elusive boundary between private citizens’ need for protection in unforeseen circumstances and their right to be free of government intrusion. The Constitution’s Fourth Amendment prohibits “unreasonable search and seizure,” a term that is still being defined in a technological age nearly 230 years later.

To search someone’s property, police ordinarily obtain a warrant from a court based on “probable cause” of incriminating evidence at the site. The issue in Monday’s case was what officers must show to justify entry without a warrant.

Police went to Ovieda’s home in June 2015 after getting messages from family members that he was suicidal and had access to a gun. They surrounded the home while Ovieda was inside with two friends, a husband and wife, who took away a gun he was trying to grab, the court said. The woman then led Ovieda outside, where police handcuffed and searched him.

Officers then entered the home, with guns drawn, in what they called a “protective sweep” to look for other weapons and see if anyone needed help, the court said. Inside, they found marijuana and drug production equipment, along with various firearms. Ovieda pleaded guilty after a trial judge ruled that the entry was legal and the evidence was admissible.

In Monday’s ruling, Justice Carol Corrigan said police had safe legal options — they could have taken Ovieda into custody for a mental health evaluation, then obtained a warrant to search his home for guns. But without a warrant or an emergency, she said, they had no justification for entering the home.

“If all that is required is the possibility that someone in some house might require aid, any officer on patrol might urge that people in homes often need help and the officer entered to make sure assistance was not required,” Corrigan said.

American Civil Liberties Union attorney Ian Kysel, who filed arguments supporting Ovieda, said the ruling “ensures that, unless there is a life-threatening emergency, a judge will issue a warrant before police can force their way into a home.”

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