President Donald Trump speaks during a meeting with patients who have recovered from the novel coronavirus, COVID-19, in the Cabinet Room of the White House in Washington, DC on April 14, 2020.

The Supreme Court on Thursday sided largely with environmentalists in a case over the reach of the landmark Clean Water Act, ruling that a "loophole" in the law backed by the Trump administration was unlawful.

The top court voted 6-3, with conservatives Chief Justice John Roberts and Justice Brett Kavanaugh joining the court's four Democratic appointees in the majority. The case is the most high-profile environmental dispute of the Supreme Court's term.

The majority ruled that the Clean Water Act forbids polluters from spewing waste into navigable waters like oceans and streams without a permit even if the pollution travels indirectly through groundwater.

But it also applied a more narrow standard than the one used by the federal appeals court that previously sided with the clean water advocates.

Maui, which brought the case, and the Trump administration's Department of Justice had argued that the law did not apply to pollution that traveled through groundwater.

Read more: Brewers warn Supreme Court: Back the Clean Water Act, or beer will taste like medicine

Justice Stephen Breyer, who authored the opinion of the court, rejected that interpretation, arguing that if it were accepted, a pipe owner could "simply move the pipe back, perhaps only a few yards, so that the pollution must travel through at least some groundwater before reaching the sea."

"We do not see how Congress could have intended to create such a large and obvious loophole in one of the key regulatory innovations of the Clean Water Act," Breyer wrote.

The case concerned Maui's Lahaina Wastewater Reclamation Facility, which treats millions of gallons of sewage each day and injects the treated waste into wells deep underground. A study ordered by the Environmental Protection Agency showed that nearly all of the waste ends up in the Pacific Ocean.

Environmental groups challenged Maui in court over the pollution, arguing that the Clean Water Act required the facility to obtain a federal permit.

Read more: Supreme Court casts doubt on Trump-backed 'loophole' in Clean Water Act

A federal district court sided with the environmentalists, and the 9th U.S. Circuit Court of Appeals affirmed the decision, saying such permits were required when pollutants are "fairly traceable" from the pipe to navigable waters, which includes the Pacific Ocean but not groundwater.

The Supreme Court said that the "fairly traceable" standard was too broad, citing the "power of modern science" to detect pollutants years after their release in minute quantities. Breyer wrote that a permit is instead required when the indirect pollution via groundwater is the "functional equivalent of a direct discharge."

"If the pipe ends 50 miles from navigable waters and the pipe emits pollutants that travel with groundwater, mix with much other material, and end up in navigable waters only many years later, the permitting requirements likely do not apply," he wrote.

David Henkin, an attorney at the environmental nonprofit Earthjustice who argued the case before the justices in November, said in a statement that the Supreme Court's opinion is "a huge victory for clean water."

"The Supreme Court has rejected the Trump administration's effort to blow a big hole in the Clean Water Act's protections for rivers, lakes, and oceans," he said.

An attorney for Maui and the Justice Department's solicitor general's office did not immediately respond to requests for comment.

The three justices who dissented from the majority opinion, Justices Neil Gorsuch, Clarence Thomas and Samuel Alito, said they would only require a federal permit for direct pollution into navigable waters.

Thomas, in a dissent joined by Gorsuch, wrote that the text of the statute only applied to direct pollution. Alito, on the other hand, wrote that there were "two ways to read this text": It could require permits for all indirect pollution, or only direct pollution.

The majority's "middle way" — the functional equivalent standard, which requires permits for only some indirect pollution — was incomprehensible, the George W. Bush appointee wrote.

"Instead of concocting our own rule, I would interpret the words of the statute, and in my view, the better of the two possible interpretations is that a permit is required when a pollutant is discharged directly from a point source to navigable waters," Alito wrote.

The case is County of Maui v. Hawaii Wildlife Fund, No. 18-260.