Supervisor Eric Mar, who co-sponsored the legislation, said there was no good reason for stores that sell nicotine patches and drugs to patients with cancer at one counter to offer cigarettes, cigars and chewing tobacco at another.
"Cigarettes and pharmacies don't mix," Mar said. "Pharmacies should promote healing and protect our health."
The ordinance expands an existing ban on drug store sales of tobacco products to cover big box wholesale clubs with pharmacies such as Costco Wholesale Corp. and grocery stores such as Safeway. A similar law is on the books with Boston.
It was opposed by businesses that say it unfairly restricts consumer choice and hurts sales in the competitive grocery retail market.
"For us it's kind of throwing the baby out with the bath water," said Safeway Inc. spokeswoman Susan Houghton. "We do obviously have healthy foods in our stores, and we do sell products that might be less healthy. For us it's about providing an array of products for our customers."
Safeway operates nine of the 14 stores that sell prescription medicine and tobacco products in the city that will now have to stop selling one or the other.
Houghton said customers would now have to go to multiple stores or leave the city in order to buy cigarettes.
The measure passed with a 7-3 vote, but it needs the board's final approval before heading to Mayor Gavin Newsom's desk for his signature. Tony Winnicker, a Newsom spokesman, said the mayor would sign the bill.
Walgreen Co. challenged the law passed in 2008 that only applied to pharmacies, saying it was unfair to discriminate in favor of large retailers.
The First District Court of Appeal agreed that the exemption for big box retailers and grocers was unfair. The new law basically brings the city into compliance with that ruling, Winnicker said.
Deerfield, Ill.-based Walgreen, which operates dozens of stores in San Francisco already affected by the law, said the amended law makes for a fairer marketplace.
"We've always felt that any regulation like this should apply to all retailers with pharmacies equally," spokesman Robert Elfinger said in a statement.
The city's ban is the latest legislative attempt in a state that has seen many efforts to limit the places where tobacco can be purchased and consumed and to increase the cost of doing so. Smoking in many public places, such as restaurants, has been prohibited since the mid-1990s.
Public health advocates say those policies have worked in stemming the life-threatening diseases, such as lung cancer, caused by smoking. A 2007 state health report prepared by professors at the University of California, San Diego found that 15 percent of San Francisco adults smoked, down from 20 percent in 1990.
Winnicker said Newsom planned to veto another law passed Tuesday by the Board of Supervisors and opposed by business groups that would levy new taxes on alcohol sales.