SAN FRANCISCO — Comparing climate change to tobacco as a major threat to humanity, San Francisco and Oakland have sued the world’s biggest oil companies in an attempt to defend against rising sea levels.

In seeking huge but unspecified sums to pay for sea walls and other shoreline defenses, the cities argue that oil companies concealed for decades that they knew fossil fuel use was dooming the Earth to global warming and rising sea levels.

The oil companies, city officials said Wednesday in announcing the lawsuit, acted much as tobacco companies did in the 1980s and 1990s when they downplayed the heavy health toll from smoking.

“These fossil fuel companies profited handsomely for decades while knowing they were putting the fate of our cities at risk,” San Francisco City Attorney Dennis Herrera said. “Instead of owning up to it, they copied a page from the Big Tobacco playbook. They launched a multimillion-dollar disinformation campaign to deny and discredit what was clear even to their own scientists: Global warming is real, and their product is a huge part of the problem.”

The lawsuits filed in Alameda and San Francisco county superior courts name Chevron, Exxon, Royal Dutch Shell, BP and Conoco Phillips.

Chevron and Shell declined to comment on specifics of the lawsuit but questioned whether the litigation by two cities was helpful in addressing the global problem of climate change.

“Chevron welcomes serious attempts to address the issue of climate change, but these suits do not do that,” the company said in a statement. “Reducing greenhouse gas emissions is a global issue that requires global engagement and action. Should this litigation proceed, it will only serve special interests at the expense of broader policy, regulatory and economic priorities.”

Oakland and San Francisco officials said climate model studies show large parts of their cities, including Oakland International Airport, will be flooded within 100 years in storm surges unless prompt and expensive measures are taken. City officials say sea levels could rise as much as 10 feet over the next century.

The lawsuits ask the courts to hold the oil companies liable for contributing to a public nuisance, and to order the oil firms to contribute to a large abatement fund to cover costs expected to run into the billions of dollars.

“The harm to our cities has commenced and will only get worse,” said Oakland City Attorney Barbara Parker. “The law is clear that the defendants are responsible for the consequences of their reckless and disastrous actions.”

A 2014 report by the National Academy of Sciences identifies the Oakland airport as vulnerable to rising sea levels. City officials also worry that rising sea levels will disrupt sewer discharges and lead to sewage overflows in some low-lying areas.

In San Francisco, officials are looking at spending some $500 million to fortify a three-mile-long seawall along the Embarcadero, and many millions more to protect the city’s combined sewer and flood water system from backups.

Rising sea levels threaten $10 billion of public property and $39 billion of private property in San Francisco, according to the lawsuit.

Shell Oil criticized the lawsuit. “We believe climate change is a complex societal challenge that should be addressed through sound government policy and cultural change to drive low-carbon choices for businesses and consumers, not by the courts,” Shell wrote.

But Ken Kimmell, president of the Union of Concerned Scientists, a nonprofit science advocacy group, praised Oakland and San Francisco for taking a “bold and necessary step to protect their communities.”

Kimmell said, “It is appropriate that people are now looking to the courts, instead of legislators, to help hold fossil fuel companies accountable for their contributions to sea level rise and other climate impacts.”

In July, San Mateo and Marin counties in the Bay Area and Imperial Beach in San Diego County filed a similar climate change lawsuit against oil companies, coal and energy companies.