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, in a 5-4 opinion by Chief Justice John Roberts, rejected 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 another 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.”

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.

Write to Brent Kendall at brent.kendall@wsj.com