By Brent Kendall and Timothy Puko

WASHINGTON -- The Supreme Court removed a legal barrier to the construction of an $8 billion pipeline that would deliver natural gas from West Virginia to the East Coast, ruling the project could run under a major hiking trail.

The court, in a 7-2 opinion by Justice Clarence Thomas on Monday, overturned a lower-court ruling that found the U.S. Forest Service didn't have the authority to grant a special-use permit that allowed developers of the Atlantic Coast Pipeline to construct an underground segment beneath a section of the Appalachian National Scenic Trail in Virginia.

The Atlantic Coast Pipeline is a partnership is a partnership in which Dominion Energy Inc. and Duke Energy Corp. are major investors. It would transport natural gas from West Virginia across 600 miles to sites in Virginia and North Carolina. The companies say the project is needed to help meet East Coast demand for cleaner-burning fuel. The pipeline was announced in 2014 but has faced delays.

Environmentalists argued the pipeline's path could harm ecologically important national forests, with threats of soil erosion and damage to wildlife habitat. They said the project would harm an especially picturesque section of the Appalachian Trail in Virginia located near Reeds Gap and the Wintergreen Resort. The trail runs more than 2,000 miles from Maine to Georgia.

The case required the high court to unwind the intersection of several federal agencies and laws, and consider what the word "land" actually means.

The Forest Service can grant a right of pipeline access on national forest land, but it can't do so on lands in the National Park System. The Appalachian Trail is administered by the National Park Service, and environmentalists argued that meant the Forest Service couldn't grant the permit.

The pipeline developers and the Trump administration, however, argued the trail, for present purposes regarding the pipeline, isn't land.

The court agreed.

"The lands that the trail crosses are still federal lands, and the Forest Service may grant a pipeline right-of-way through them -- just as it granted a right-of-way for the trail," Justice Thomas wrote. "Sometimes a complicated regulatory scheme may cause us to miss the forest for the trees, but at bottom, these cases boil down to a simple proposition: A trail is a trail, and land is land."

For the dissent, Justice Sonia Sotomayor, joined by Justice Elena Kagan, said the ruling "condones the placement of a pipeline that subverts the plain text of the statutes governing the Appalachian Trail."

The win for energy companies is the biggest court decision yet in a nationwide legal fight over the expansion of interstate pipelines and the use of fossil fuels. Energy companies have met opposition from environmentalists concerned about climate change and the chance of more spills and leaks as North America produces more oil and gas. That opposition has repeatedly blocked connections producers need to continue unlocking new supply from the fracking boom.

The long-delayed Keystone XL oil line from Canada has been waylaid for a decade by federal reviews, the courts and fights in front of state commissions. And the Atlantic Coast Pipeline is one of several long-haul natural-gas projects that need to overcome hurdles in the Eastern U.S., where some states have joined the fight to keep new pipelines from taking a glut of Appalachian gas to New York, New England and the Southeast.

Atlantic Coast's partners cheered Monday's decision and said it follows longstanding precedent allowing infrastructure projects to cross the trail. They said the current gas bottleneck is so tight that some industrial customers get cut off on cold days when demand for gas heat is high. And they said the project will bring jobs and cheaper power to needy communities across Virginia and North Carolina and provide cleaner energy than coal.

The Atlantic Coast Pipeline is needed now more than ever for our region's economy and our path to clean energy," Dominion Energy and Duke Energy said in a joint statement. "They urgently need new infrastructure to support military bases, manufacturing and home heating."

But officials also acknowledged that the project has other environmental reviews and permitting hurdles it has to clear. And analysts and environmentalists say that those could still scuttle Atlantic Coast despite Monday's ruling.

Environmentalists said the fight will go on and that the developers should redirect the project's money to investments in renewable energy. They pointed out that since the project's proposal six years ago, both North Carolina and Virginia have set plans to reduce their greenhouse-gas emissions that cause climate change, including a law from Virginia that would require all Dominion's gas-fired power plants to close -- or to capture their emissions -- by 2045.

"While today's decision was not what we hoped for, it addresses only one of the many problems faced by the Atlantic Coast Pipeline," DJ Gerken, program director with the Southern Environmental Law Center, said in a statement issued with the Sierra Club. "This is not a viable project."

Analysts at Jefferies LLC and Credit Suisse Group AG said the high court's decision clears the project's biggest obstacle. And the Washington-based analysis firm ClearView Energy Partners LLC says the project is a prime candidate for having U.S. Forest Service permits expedited under an order President Trump signed this month for federal agencies to use emergency authority to sidestep some environmental reviews.

But analysts also urged caution in assuming the decision might foreshadow more success or a major breakthrough for gas producers looking to get a supply glut out of Appalachia. Its reach is likely too narrow to help jump-start other ongoing projects, and will do little to eliminate many other avenues environmentalists or reluctant states have to slow pipeline development, analysts said.

Sign up for WSJ's free Capital Journal newsletter here.

Write to Brent Kendall at brent.kendall@wsj.com and Timothy Puko at tim.puko@wsj.com