Four Massachusetts teens who say they were sick of watching the state drag its feet on global warming went to court — and yesterday came away with a historic victory that could have lasting effects for decades.

The Supreme Judicial Court has sided with Olivia Gieger and Shamus Miller of Wellesley High School, and Isabel Kain and James Coakley of Boston Latin School — high school kids who sued the Department of Environmental Protection. The court agreed with them that the state has failed to fulfill its legal obligation to reduce greenhouse gas emissions.

“It’s so surreal. I always ?believed in what we were doing, so it was such an amazing moment to see the results,” said Gieger, 17. “It’s amazing to see what effect we can have.”

The students were joined by the Mass Energy Consumers Alliance and lawyers from the Conservation Law Foundation. They argued that the state misinterpreted the Global Warming Solutions Act — a 2008 state law that requires a 25-percent reduction of greenhouse gas emissions by 2020 and an 80-percent ?reduction by 2050.

They said the Department of Environmental Protection failed to create effective regulations as required by the law, and set back the “commonwealth’s efforts to mitigate climate change impacts,” according to the suit.

The SJC unanimously agreed, and Justice Robert Cordy wrote that the department has to act now and create regulations that address greenhouse gas emissions, set emission limits for each year and make sure those limits decline “on an annual basis.”

“I was in school and I ran to tell Olivia that it worked out that way,” Miller said. “I kept telling her, ‘We won! We won!’ It was such a great day for us and the people in Massachusetts.”

The students sat in the ?Supreme Judicial Court in early January as their attorneys and lawyers from the attorney general’s office did battle. “It was ?intimidating,” Gieger said, but she had a feeling her side had ?better arguments.

Hours after the decision came down, Attorney General Maura Healey congratulated members of Mothers Out Front — a Cambridge-based nonprofit fighting to raise awareness of climate change, which also filed an ?amicus brief in the suit.

“The Supreme (Judicial) Court said today that Mothers Out Front was right — this needs to happen and in a unanimous decision decided that this will happen and so congratulations to all of you,” Healey said at a luncheon, according to a transcript of the event.

The Executive Office of Energy and Environmental Affairs said in a statement that the state is “currently reviewing the Supreme Judicial Court’s ruling.” It did not respond to a question about how much it will cost to make the changes.

For four teens and a handful of lawyers, yesterday’s massive victory will resonate for years to come.

“This is far more than a symbolic ruling,” said Conservation Law attorney Jennifer K. Rushlow. “This requires real action, now.”