LOS ANGELES  The City Council approved an ordinance on Tuesday that would shutter the majority of the nearly 1,000 medical marijuana dispensaries in Los Angeles and make the use of marijuana in the remaining outlets illegal.

The vote is a major setback for backers of medical marijuana and a victory for community groups that have long complained about the proliferation of the dispensaries near residential neighborhoods, schools and parks. Los Angeles has more of the outlets than any other city in the dozen or so states that allow the use of marijuana for medical purposes.

“These are out of control,” Councilman Ed Reyes, chairman of the Council’s planning and land-use management committee, who oversaw the writing of the ordinance, said in an interview at City Hall. “Our city has more of these than Starbuckses.”

California voters approved the use of marijuana for medical purposes in 1996, and cities have since struggled with how best to regulate its distribution. Under the law, individuals and cooperatives were permitted to cultivate marijuana for medical use. Dispensaries selling marijuana, often for profit, quickly popped up around the state.