A number of recent legal defeats and business decisions have stymied three multibillion-dollar pipeline projects around the country, setting back President Trump’s 3½-year effort to expand oil and gas development in the United States.

The reversals demonstrate both the enduring power of environmental laws that the Trump administration has been trying to weaken and the tenacity of environmental, tribal and community activists who have battled the projects on forested land and in federal courtrooms.

In a surprise decision Monday, a federal judge ruled that the Dakota Access pipeline — which Trump approved within a month of taking office — must be shut down by Aug. 5, saying federal officials failed to carry out a complete analysis of its environmental impacts. The day before, two energy companies behind the controversial, 600-mile Atlantic Coast Pipeline abandoned their six-year bid to build it, saying the $8 billion project has become too expensive and faces an uncertain regulatory environment. And an April decision by a federal judge in Montana dealt a blow to the Keystone XL pipeline and raised questions about whether the U.S. Army Corps of Engineers will have to conduct more extensive environmental reviews for other projects.

Our system is set up so that it’s very unusual for the president to be able simply to snap his or her fingers and make something change,” said Joel Reynolds, a senior attorney for the Natural Resources Defense Council Action Fund, in a phone interview. “We have checks and balances. We have statutes that lay out legal procedures to be followed. It’s one thing to talk about deregulation; it’s quite another thing to do it.”

American Petroleum Institute President Mike Sommers said in a statement Monday that his trade group was “deeply troubled by these setbacks for U.S. energy leadership.”

“Our nation’s outdated and convoluted permitting rules are opening the door for a barrage of baseless, activist-led litigation, undermining American energy progress and denying local communities the environmental, employment and economic benefits modern pipelines provide,” Sommers said. “The need to reform our broken permitting system has never been more urgent.”

The window is closing for Trump to be able to shepherd through these proposals before the end of his first term. Former vice president Joe Biden, the presumptive Democratic nominee who is leading the president in several polls, has said he will rescind Keystone XL’s federal permit and says he would weigh any project’s contribution to climate change before approving it. Burning oil and gas produces carbon dioxide, a greenhouse gas linked to global warming.

During a League of Conservation Voters virtual event last month, Biden said that if elected he would be “requiring that there must be a full review and accounting of the impacts on climate, local, and environmental health, and climate justice before any project can proceed.”

The outcome of projects hanging in the balance could have major implications for climate change, because pipelines built today could be shipping oil and gas for decades.

In several instances, long-standing statutes such as the National Environmental Policy Act, which requires federal agencies to assess and disclose how their decisions might harm the environment, have tripped up the administration. In his ruling regarding the Dakota Access pipeline, U.S. District Judge James E. Boasberg wrote that the federal government had not met all the requirements of the 50-year-old-law, which the administration is seeking to rewrite.

The $3.8 billion Dakota Access pipeline, which opened in 2017, carries about half a million barrels of crude oil a day from North Dakota’s Bakken shale basin across 1,100 miles to Illinois. The ruling means the Army Corps of Engineers must conduct a more thorough analysis of how a leak in the Dakota pipeline could affect Lake Oahe, which collects water from the Missouri River and lies half a mile from the Standing Rock Indian Reservation.

Several tribes, including the Standing Rock Sioux and Cheyenne River Sioux, first challenged the pipeline in 2016. While the Obama administration slowed the pipeline’s development as it consulted with the tribes, Trump expedited its construction immediately after taking office.

“Today is a historic day for the Standing Rock Sioux Tribe and the many people who have supported us in the fight against the pipeline,” said the tribe’s chairman, Mike Faith, in a statement. “This pipeline should have never been built here. We told them that from the beginning.”

Jan Hasselman, a lawyer with Earthjustice who has led the legal battle on behalf of the Standing Rock Sioux, said in an interview, “I can’t think of another example where a major piece of infrastructure was shut down after being in operation a couple of years.”

Energy Transfer Partners, which owns the largest stake in the Dakota Access line, called the court order “an ill-thought-out decision” and said it would immediately seek a stay so that oil could continue to flow. If the stay is not granted, company officials said, they will file an expedited appeal.

The company said the court order would hurt state, local and tribal tax revenue and force oil producers to move oil by railroad, which Energy Transfer Partners said was more dangerous. Its shares plunged more than 12 percent Monday, closing at $6.17 a share.

Energy Transfer Partners has close ties to the Trump administration. Last month, the company’s CEO, Kelcy Warren, held a fundraiser for the president in his home, and former energy secretary Rick Perry rejoined the company’s board just months after stepping down from the Cabinet.

The company has been involved in other controversial projects, including the Rover natural gas pipeline that spilled drilling fluids in Ohio during construction and led to the demolition of a historic home, contrary to an order by the Federal Energy Regulatory Commission.

During his first week in office, Trump tried to speed up work on the Dakota Access and Keystone XL pipelines by issuing executive orders aimed at overcoming regulatory obstacles. But years later, the owners of both pipelines are still fighting in court against opponents.

Recently, Trump has sought to speed the development of pipelines and other infrastructure projects by executive order. He has tried to waive environmental permitting laws, citing the need to bolster the economy during the coronavirus pandemic. Last month, the Environmental Protection Agency also proposed limiting the ability of states and tribes to block pipelines and other infrastructure projects that could pollute their waterways.

The White House is also expected to finalize within a matter of weeks a rule that would scale back the National Environmental Policy Act by limiting the extent to which climate change could be considered in federal approval for various projects.

Despite those efforts, major drilling, mining and pipeline projects continue to face stiff head winds. And activists of color have been leading the opposition at sites across the nation — from the Great Plains to the Southeast and Alaska.

In the case of the Atlantic Coast pipeline, African American leaders had joined with property rights advocates in the Appalachians to fight the pipeline project, which included a compressor station that would have been built in Union Hill, a historic African American community.

Another major project with environmental risks and long-running political battles is Pebble Mine, a project that if approved would tap a massive gold and copper deposit near the world’s largest sockeye salmon fishery in Alaska’s Bristol Bay. The Trump administration has worked to clear the way for the project, even as opponents argue that the mine poses grave environmental risks.

Bristol Bay Native Corp. CEO Jason Metrokin noted that documents his Alaska Native corporation obtained under the Freedom of Information Act show that both state and federal wildlife agencies, as well as the EPA, have warned the mine could have major impacts. But the Trump administration has forged ahead, he said.

“It’s been rushed, it’s been closed door, and they haven’t taken into account the number of concerns coming from both state and federal agencies, our congressional delegation and the public at large,” Metrokin said of the permitting process.

Reynolds said that if Biden were elected, he would probably halt Pebble Mine. But he added that with that project, as with other major proposals, opponents have other avenues to pursue that go beyond the reach of any one administration.

“The opposition to this project is never going to stop,” he said. “There are state-level permits, there are other federal agencies, there are financial issues. … There’s only so much that even a president can do.”

Oil and gas executives, meanwhile, have been appealing to the White House for help. On June 12, representatives from more than a dozen firms and the American Petroleum Institute met with officials from the White House Office of Information and Regulatory Affairs to discuss nationwide permitting rules, according to federal records.

An API official said in an email that the session was “a routine meeting” to discuss nationwide permits to be put up this year. But two individuals familiar with the meeting, who spoke on the condition of anonymity to discuss private deliberations, said the executives voiced concern about the April court ruling halting Keystone XL.

On Monday the Supreme Court rejected the administration’s petition to lift the stay on Keystone XL issued in April, but allowed the Army Corps to resume issuing permits for other oil and gas pipelines.

Jeff Stein contributed to this report.