Just as pressure was building on President Barack Obama to make a decision on the Keystone XL pipeline that would carry oil from Canada to refineries in Texas, the project ran into another obstacle after a judge in Nebraska overturned a state law approving the pipeline.

The legal fight over the pipeline will continue for at least several more months after the judge's ruling Wednesday, which was a victory for pipeline opponents, including environmentalists who say Keystone XL would carry "dirty oil" that contributes to global warming and Nebraska ranchers and farmers who fear it could hurt their water supply.

TransCanada Corp.'s pipeline is critical in Canada's efforts to export its growing oil sands production. It would carry 830,000 barrels of oil daily from Canada to Texas Gulf Coast refineries. Supporters say it will create thousands of jobs and move the U.S. toward North American energy independence.

The other states along the pipeline's route — Montana, South Dakota, Nebraska, Kansas, Oklahoma and Texas — have already approved their segments. Oil is already flowing through the Oklahoma-to-Texas segment.

TransCanada officials have said passing through Nebraska is the most direct, practical way to transport the oil. And rerouting the pipeline would bring new states into the mix and would lead to further expensive delays.

At issue in Wednesday's ruling was a 2012 law that allowed Gov. Dave Heineman to approve the route through Nebraska. The governor's approval gave Calgary-based TransCanada the power to use eminent domain on landowners who deny the company access to their property. Three landowners filed a lawsuit saying the decision should have been made by the Public Service Commission.

Lancaster County Judge Stephanie Stacy agreed.

Attorney General Jon Bruning's office plans to appeal the ruling to the Nebraska Supreme Court.

A spokesman for pipeline developer TransCanada said company officials were disappointed and disagreed with the decision. The company planned to review the ruling before deciding how to proceed.

"TransCanada continues to believe strongly in Keystone XL and the benefits it would provide to Americans — thousands of jobs and a secure supply of crude oil from a trusted neighbor in Canada," said spokesman Shawn Howard.

Daniel J. Weiss, senior fellow and director of climate strategy with left-leaning think tank Center for American Progress, said Obama and Secretary of State John Kerry will probably wait until Nebraska has legally approved the pipeline route before making any decision on whether to give federal approval to the pipeline.

"This court decision provides more uncertainty for pipeline proponents, and more time to organize for pipeline opponents," Weiss said.

The decision on a federal permit for the northern leg of the route still rests with Obama, five years after backers first asked his administration for approval.

Obama blocked the Keystone XL pipeline in January 2012, saying he did not have enough time for a fair review before a looming deadline forced on him by congressional Republicans. But late last month, the U.S. State Department released an environmental analysis that raised no major environmental objections to the $7 billion pipeline, though opponents disagree.

U.S. State Department spokesman Douglas Frantz said officials were aware of the Nebraska ruling but would not comment because the case was ongoing.

It's not the first time Nebraska has been an obstacle in TransCanada's efforts to complete the pipeline.

An earlier proposed route drew fierce opposition because landowners said it would threaten the Nebraska Sandhills, a region of grass-covered dunes used as ranchland. That prompted the state Legislature to pass a law in 2012 giving Gov. Dave Heineman the authority to approve the route. The new one he approved goes around an area designated as the Sandhills, although opponents insist it still traverses the delicate soil.

Randy Thompson, a Nebraska rancher and a leading plaintiff in the lawsuit, became involved in the dispute after he was notified that the original Keystone XL route would have crossed his parents' 400-acre farm in Merrick County. He said he doesn't think TransCanada should be able to force landowners to sign pipeline contracts using eminent domain.