BERKELEY, Calif.—Voters in a California city known for free speech and tolerance have narrowly struck down a measure that would have banned sitting and lying on streets and sidewalks.

Berkeley's Measure S was rejected 51 percent to 48 percent on Tuesday.

It would have made it a crime to sit or lie on sidewalks from 7 a.m. to 10 p.m. in commercial areas. Similar laws have been adopted in San Francisco, Santa Cruz, Palo Alto and Los Angeles.

Berkley's vote came after months of heated debate. Supporters said the measure would help businesses whose storefronts are often blocked by groups camping out.

Opponents said the proposal was severe. It carried citations and a possible maximum sentence of six months jail.