SAN FRANCISCO (AP) — A U.S. judge who held a hearing about climate change that received widespread attention ruled Monday that Congress and the president were best suited to address the contribution of fossil fuels to global warming, throwing out lawsuits that sought to hold big oil companies liable for the Earth’s changing environment.

Noting that the world has also benefited significantly from oil and other fossil fuel, Judge William Alsup said questions about how to balance the “worldwide positives of the energy” against its role in global warming “demand the expertise of our environmental agencies, our diplomats, our Executive, and at least the Senate.”

“The problem deserves a solution on a more vast scale than can be supplied by a district judge or jury in a public nuisance case,” he said.

Alsup’s ruling came in lawsuits brought by San Francisco and neighboring Oakland that accused Chevron, Exxon Mobil, ConocoPhillips, BP and Royal Dutch Shell of long knowing that fossil fuels posed serious risks to the environment, but still promoting them as environmentally responsible.

The lawsuits said the companies created a public nuisance and should pay for sea walls and other infrastructure to protect against the effects of climate change — construction that could cost billions of dollars.

The Oakland city attorney’s offices did not immediately have comment. John Cote, a spokesman for the San Francisco city attorney’s office, said the office was reviewing the ruling and would decide its next steps “shortly,” but the lawsuit had “forced a public court proceeding on climate science.”

“We’re pleased that the court recognized that the science of global warming is no longer in dispute,” he said.

New York City, several California counties and at least one other California city filed similar suits.

The companies said federal law controlled fossil fuel production, and Congress encouraged oil and gas development. The harm the cities claimed was “speculative” and part of a complex chain of events that included billions of oil and gas users and “environmental phenomena occurring worldwide over many decades,” they said in court documents.

National Association of Manufacturers President and CEO Jay Timmons applauded the ruling in a statement. “From the moment these baseless lawsuits were filed, we have argued that the courtroom was not the proper venue to address this global challenge,” said Timmons.

Alsup brought in the world’s leading experts on climate change at an unusual hearing in March that he said was intended to educate him about the science behind the Earth’s warming.

The nearly five-hour hearing covered topics including the history of climate change research, carbon dioxide’s role as a greenhouse gas, melting ice caps, rising sea levels and extreme weather.

In Monday’s ruling, the judge said he accepted the “vast scientific consensus” that the combustion of fossil fuels has contributed to global warming and rising sea levels. But he questioned whether it would be fair to “ignore our own responsibility in the use of fossil fuels and place the blame for global warming on those who supplied what we demanded.”