Part of the controversial Keystone Pipeline was shut down Thursday after more than 200,000 gallons of oil leaked in South Dakota, the state and the company that runs the pipeline said Thursday.

Brian Walsh, an environmental scientist for the Ground Water Quality Program of the state Department of Environment and Natural Resources, told NBC News that TransCanada, the Calgary-based company that operates the Canada-to-Texas line, reported the leak Thursday morning in a sparsely populated area of Marshall County, near Amherst in the northeastern part of the state.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

In a statement, TransCanada said the pipeline was shut off from Hardisty in the Canadian province of Alberta to Cushing, Oklahoma, and to Wood River and Patoka in Illinois. The southern leg of the system, which stretches to the Mississippi Gulf Coast, remains open, it said.

Image of Amherst incident taken earlier today by aerial patrol as part of our initial response. For more updates, visit https://t.co/8yWI1Oq2EM pic.twitter.com/uRNtYUdVjL — TransCanada (@TransCanada) November 16, 2017

The company said it detected a drop in pressure overnight and safely shut off the stretches of pipeline within 15 minutes at about 6 a.m. (7 a.m. ET). It estimated the leak at 5,000 barrels, or about 210,000 gallons, but provided no information on a possible cause or when the pipeline might reopen.

Walsh said the oil appeared to be contained to an agricultural area and hadn't reached any bodies of water.

We are currently responding to an incident in Amherst, SD. We have activated emergency response procedures and dispatched ground crews to assess the situation. https://t.co/oFyyU5YYo0 — TransCanada (@TransCanada) November 16, 2017

The leak comes four days before Nebraska officials are scheduled to vote on whether to approve a 275-mile-long extension of the project through the state. State approval is needed after President Donald Trump revived the project, called Keystone XL, even though it had been rejected by the Obama administration.

"We've always said it's not a question of whether a pipeline will spill, but when, and today TransCanada is making our case for us," said Kelly Martin, director of the Sierra Club's "Beyond Dirty Fuels" campaign.

"This is not the first time TransCanada's pipeline has spilled toxic tar sands, and it won't be the last," Martin said in a statement. "There is no such thing as a safe tar sands pipeline, and the only way to protect Nebraska communities from more tar sands spills is to say no to Keystone XL."

Thursday's leak is about 12 times the size of the last major leak on a Keystone line, in April 2016 in Hutchinson County, South Dakota. According to federal records, that leak, which was eventually blamed on a "weld anomaly," was initially reported at 4½ barrels, or 187 gallons. But five days later, it was revised to 400 barrels, or 16,800 gallons.