WASHINGTON, May 17 (Reuters) - The U.S. Supreme Court on Monday ruled in favor of BP PLC, Chevron Corp, Exxon Mobil Corp, Royal Dutch Shell PLC and other energy companies contesting a lawsuit filed by the city of Baltimore seeking monetary damages from them due to costs caused by global climate change.

The 7-1 ruling came on a technical legal issue that could help the companies in their effort to have the case heard in federal court, as they would prefer, instead of state court, which the city favors as it is seen as a more amenable venue.

The high court decided that the Richmond, Virginia-based 4th U.S. Circuit Court of Appeals did not correctly analyze whether the case could be heard in federal court.

The Democratic-governed Maryland city's lawsuit targeted 21 U.S. and foreign energy companies that extract, produce, distribute or sell fossil fuels, arguing that their activities contribute to emissions of carbon dioxide and other so-called greenhouse gases linked to climate change. An important port city, Baltimore noted that it is vulnerable to sea-level rise and flooding driven by climate change.

The Supreme Court's ruling could affect around a dozen similar lawsuits brought by various U.S. states, cities and counties.

One justice, Samuel Alito, did not participate in the case, likely because he owns stocks in two oil companies involved in the litigation. (Reporting by Lawrence Hurley; Editing by Will Dunham)