WASHINGTON—The Supreme Court on Tuesday removed a hurdle to the construction of a natural-gas pipeline through Pennsylvania and New Jersey, ruling the pipeline developer could invoke the power of the federal government to take state property needed for the project.

The court’s 5-4 opinion, by Chief Justice John Roberts, handed a considerable victory to the natural-gas industry by rejecting New Jersey’s challenge to the actions of the PennEast Pipeline Co., a joint venture of several energy companies that aims to build a 116-mile interstate pipeline.

The Federal Energy Regulatory Commission authorized the project and, under the Natural Gas Act, that approval allowed the company to use federal eminent domain power to take possession of the land, if necessary.

PennEast said it was able to negotiate rights of way with most property owners, but went to court in its bid to take dozens of parcels of land—with compensation—in which the state of New Jersey holds a property interest.

New Jersey objected on sovereign-immunity grounds, arguing that a private party like PennEast, a Delaware company, can’t drag a sovereign state into federal court against that state’s wishes.

The Supreme Court rejected that argument.

“Although nonconsenting States are generally immune from suit, they surrendered their immunity from the exercise of the federal eminent domain power when they ratified the Constitution,” Chief Justice Roberts wrote for the majority.

The federal government, he said, could delegate that power to private parties who “can initiate condemnation proceedings, including against state-owned property.” The court said such delegations have been present—and lawful—throughout the nation’s history.

The decision reversed an appeals court ruling in New Jersey’s favor, restoring the status quo and giving the energy industry, under FERC oversight, broad power to use eminent domain to help build pipelines that cross state lines. PennEast said the ruling would preserve the industry’s ability to deliver low-cost natural gas at affordable prices.

What the ruling may not do, however, is save PennEast itself, said Christi Tezak, managing director at Clearview Energy Partners LLC. It faces further challenges from environmental groups out of New Jersey over its greenhouse-gas emissions and its necessity for consumers, likely leading to extensive further delays that could kill the project.

“It was a very important case to the industry,” Ms. Tezak said. But “it’s not going to release PennEast for clear sailing.”

New Jersey Attorney General Gurbir Grewal said the state was disappointed in the ruling but would continue fighting the pipeline’s construction, “which is unnecessary and would be destructive to New Jersey lands,” through other ongoing legal challenges.

An ideological mix of justices formed both the majority and the dissent.

Joining the chief justice were two fellow conservatives, Justices Samuel Alito and Brett Kavanaugh, and two liberals, Justices Stephen Breyer and Sonia Sotomayor.

Justice Amy Coney Barrett wrote the lead dissenting opinion, joined by two other conservatives, Justices Clarence Thomas and Neil Gorsuch, as well as Justice Elena Kagan, a member of the court’s liberal wing. The court, Justice Barrett said, used the wrong analytical framework and misread the historical record.

Congress, she said, enacted the Natural Gas Act under its constitutional power to regulate interstate commerce, but that power doesn’t allow lawmakers to strip states of their sovereign immunity, which “limits how Congress can obtain state property for pipelines.”

PennEast is one of several pipelines in recent years to get wrapped up in major court fights because of growing environmental opposition and a push from governments to move to cleaner fuels. A year ago, Duke Energy Corp. and Dominion Energy Inc. abandoned the Atlantic Coast Pipeline project just weeks after a favorable Supreme Court ruling over whether the project could cut under the historic Appalachian Trail.

Environmental activists have put pressure on states to block these projects, saying pipelines enable a dependence on fossil fuels and spread the environmental damage they can cause. While natural gas burns cleaner than other types of fossil fuel, leaks from the country’s pipeline, processing and storage network may make gas consumption just as big of a contributor to climate change.

State governments have only in recent years started to fight against the industry’s eminent domain power, among many efforts to respond to activists’ pressure and show they are taking action on climate change.

For a decade, the shale drilling and hydraulic fracturing boom has produced a glut of low-cost supply from places like Pennsylvania, Ohio and Texas. With prices at times hitting historic lows, the industry has pushed the country to consume more natural gas, proposing several major interstate pipelines to carry gas from the landlocked areas where it is produced to population centers and export terminals on the coasts.

Several of the largest trade groups representing natural-gas producers and transmission and distribution companies had intervened in the PennEast case, asking for the court’s help to preserve the eminent domain power. The Interstate Natural Gas Association of America, the American Petroleum Institute and the American Gas Association had said losing the case would be a serious threat to their ability to build out and operate the country’s gas pipeline network.

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