A federal judge on Monday dismissed lawsuits by the cities of San Francisco and Oakland alleging that five of the world’s largest oil companies should pay to protect the cities’ residents from the impacts of climate change.

U.S. District Judge William Alsup granted a motion by the companies — BP PLC BP, +0.08% , Royal Dutch Shell PLC RDS.A, +1.45% , Exxon Mobil Corp. XOM, -0.05% , ConocoPhillips COP, +2.20% and Chevron Corp. CVX, -0.09% — to dismiss the suits, ruling that while global warming was a real threat, it must be fixed “by our political branches.”