But the move triggered a swift backlash from critics who say it could drive former smokers back to conventional cigarettes.
US health authorities are alarmed by the rise in popularity of e-cigarettes, battery-powered devices that enable users to inhale addictive nicotine liquids that are often fruit flavoured.
The potential health consequences of vaping, including fears it could stunt adolescent development, remain largely unknown, in part because the practice is so new.
The number of young Americans using e-cigarettes grew by 1.5 million in 2018, with about 3.6 million middle and high school students using vaping products.
San Francisco is home to market-leading e-cigarette maker Juul.
City Attorney Dennis Herrera, who co-sponsored the ban, said it closed a loophole that the federal US Food and Drug Administration should have tackled long ago.
"E-cigarettes are a product that, by law, are not allowed on the market without FDA review," he said in a statement after the second and final vote to implement the ban.
"For some reason, the FDA has so far refused to follow the law. If the federal government is not going to act, San Francisco will."
The city's mayor London Breed has 10 days to sign the legislation - which she has said she will do - with the ban due to take effect seven months later.
"We need to take action to protect the health of San Francisco's youth and prevent the next generation of San Franciscans from becoming addicted to these products," Breed said in a statement Tuesday ahead of the vote.
She added that e-cigarette companies were "targeting our kids in their advertising and getting them hooked on addictive nicotine products."
But critics say the legislation will make it harder for people seeking alternatives to regular cigarettes.
E-cigarettes do not contain the cancer-causing products found in tobacco.
An editorial in the Los Angeles Times noted that regular cigarettes were still for sale in San Francisco, arguing that "it's bad public health policy to come down harder on the lesser of two tobacco evils."
Juul said in a statement following the vote that the ban would "drive former adult smokers who successfully switched to vapor products back to deadly cigarettes, deny the opportunity to switch for current adult smokers, and create a thriving black market."
The manufacturer called instead for stricter regulation and enforcement including proof-of-age identification.
Traditional "Big Tobacco" companies have increasingly marketed "smoke-free" products like e-cigarettes as far less harmful alternatives to the deadly habit they have long been peddling.
But experts point out that it took decades to determine that smoking tobacco - which accounts for more than seven million premature deaths worldwide every year - is truly dangerous.
The San Francisco ordinance text said that nicotine exposure during adolescence "can harm the developing brain" and "can also increase risk for future addiction to other drugs."
It would introduce fines of up $US1,000 ($1,431) for each violation by vendors.
Unlike an e-cigarette ban in force in Singapore, the San Francisco legislation does not restrict the use of vaping products - only sales, manufacturing and distribution.
Recreational cannabis use has been legal for adults in California since January last year.