Democrats in the US congress say the ruling could increase the pressure on politicians to push forward with the first-ever caps on carbon dioxide emissions.
Greenhouse gases are covered by the Clean Air Act as they are air pollutants, justice John Paul Stevens said in his majority opinion.
He wrote that the agency's decision was "arbitrary, capricious or otherwise not in accordance with law".
Stevens said the EPA can avoid regulation only if it determined that the gases do not contribute to climate change or if it provided a reasonable explanation.
|"Today the nation's highest court has set the White House straight"|
David Doniger, Natural Resources Defence Council
The court said the agency has so far provided a "laundry list" of reasons that include foreign policy considerations.
The EPA said the administration was committed to reducing greenhouse gases and it was "reviewing the court's decision to determine the appropriate course of action".
The state and enviromental groups that brought the lawsuit welcomed the ruling.
David Doniger of the Natural Resources Defence Council said: "Today the nation's highest court has set the White House straight.
"Carbon dioxide is an air pollutant, and the Clean Air Act gives EPA the power to start cutting the pollution from new vehicles that is wreaking havoc with our climate."
The court's four most conservative members - chief justice John Roberts and justice Samuel Alito, both Bush appointees, and justices Antonin Scalia and Clarence Thomas - had argued that the groups lacked the legal right to bring the lawsuit in the first place.
"No matter how important the underlying policy issues at stake, this court has no business substituting its own desired outcome for the reasoned judgement of the responsible agency," Scalia wrote.
The United States is the world's largest producer of such gases.
Business leaders are saying that they are increasingly open to congressional action to reduce greenhouse gases emissions, of which carbon dioxide is the largest.