(Adds details on Keystone XL and prices, background)
CALGARY, Alberta, Nov 16 (Reuters) - TransCanada Corp shut part of its Keystone oil pipeline system after a 5,000-barrel leak in South Dakota, the company said on Thursday, four days before neighboring Nebraska was set to decide on the company's long-delayed Keystone XL pipeline.
Opponents of TransCanada's proposed Keystone XL pipeline seized on the spill, saying it highlighted the risks posed by the XL project - which has become a symbol for environmentalists of fossil-fuel pollution and global warming.
TransCanada said in a statement it discovered the leak in the town of Amherst at 6 a.m. on Thursday after systems detected a drop in pressure, and that it was working with authorities as it investigates the cause.
South Dakota Department of Environmental and Natural Resources spokesman Brian Walsh said the leak came from an underground pipeline and that it had been contained at the site.
U.S. President Donald Trump has made Keystone XL a key plank in his energy policy and handed TransCanada a federal permit in March, reversing former President Barack Obama's decision to reject the line on environmental grounds after years of study.
Trump has argued that the 830,000-barrel pipeline, which would serve as an extension of the existing Keystone system linking Alberta oil to U.S. refineries, will lower fuel prices, shore up national security and bring jobs.
TransCanada and its supporters have also said the project would bring significant economic benefits, and could be operated safely.
"If this spill had happened along the proposed route in Nebraska, it would be absolutely devastating," said Brian Jorde, a lawyer representing Nebraska landowners opposed to Keystone XL. "Their proposed route is within a mile of thousands of water wells."
"We hope the PSC is paying attention," said Greenpeace campaigner Mike Hudema, referring to the regulatory body that will rule on XL.
The Nebraska Public Service Commission, or PSC, is scheduled on Monday to announce a decision on whether the proposed pipeline route through the state is in the best interests of Nebraskans. It is not allowed to consider the potential of spills as the project already has an environmental permit.
A rejection of the route would dim the chances the project gets built and would be a setback for both Trump and the Canadian energy sector, which says it needs more export routes to fetch better prices.
Other states have already approved XL's route.
TransCanada said the spill in South Dakota had led the company to shut the Keystone pipeline from Hardisty, Alberta, to Cushing, Oklahoma, and to Wood River and Patoka in Illinois. It said the southern leg of the system to the Gulf Coast remained operational.
Canadian heavy crude differentials for December delivery in Hardisty, Alberta, widened to $14.65 per barrel below U.S. crude from a discount of around $14.20 per barrel the previous day.
Thursday was the last day of the Canadian crude trading window, meaning volumes were thin, but traders said the sell-off could deepen if it appeared the pipeline would be down for some time, leading to a glut of crude in Alberta.
Canadian heavy crude for January delivery also widened 40 cents to $15.50 per barrel below U.S. crude. (Reporting by Ethan Lou and Nia Williams in Calgary, Alberta; Editing by Richard Valdman and Peter Cooney)