President Donald Trump speaks while meeting with senior administration officials in the Cabinet Room of the White House in Washington on April 9, 2018, as national security adviser John Bolton looks on.

WASHINGTON — As the president's top aides prepared for a high-stakes meeting on the future of Afghanistan earlier this month, one senior official was not on the original invite list: national security adviser John Bolton.

The attendance of the top security aide would normally be critical, but the omission was no mistake, senior U.S. officials said. Bolton, who has long advocated an expansive military presence around the world, has become a staunch internal foe of an emerging peace deal aimed at ending America's longest war, the officials said.

His opposition to the diplomatic effort in Afghanistan has irritated President Trump, these officials said, and led aides to leave the National Security Council out of sensitive discussions about the agreement.

The sidelining of Bolton has raised questions about his influence in an administration that is seeking a troop withdrawal from Afghanistan as well as an ambitious nuclear deal with North Korea and potential engagement with Iranian President Hassan Rouhani. Bolton, U.S. officials said, stands in opposition to those efforts but he does so increasingly from the periphery.

"It's messed up on so many levels that the national security adviser isn't involved, but trust is a real issue," said a senior U.S. official, one of a half-dozen who spoke on the condition of anonymity to discuss internal conversations.

At the zenith of his influence, Bolton enabled the president to act on his most aggressive instincts and outmaneuvered other Cabinet officials with less experience in the interagency process. But his tough management style and bellicose worldview have frayed relations with some colleagues.

In a recent standoff, Bolton asked for a copy of the draft agreement the United States is trying to strike with the Taliban. But the U.S. envoy leading the negotiations, Zalmay Khalilzad, denied the request, saying Bolton could read the agreement in the presence of a senior official but not leave with it in hand, U.S. officials said. One official said the incident infuriated Bolton while another downplayed it, saying the draft was eventually sent to the National Security Council staff.

"I can't think of another example where a national security adviser was sidelined like this," said Tom Wright, an international security expert at the Brookings Institution. "One thing that makes this different from normal bureaucratic infighting is that Bolton has pitted himself against a policy the president clearly supports."

On Thursday, Trump said in a Fox News interview he plans to draw down the number of U.S. troops in Afghanistan to 8,600 and "then we make a determination from there as to what happens." Bolton is not fighting that partial withdrawal decision, but U.S. officials said he remains deeply opposed to Khalilzad's emerging deal. The agreement would see the partial removal of U.S. troops in exchange for the Taliban renouncing al-Qaeda and preventing the group from recruiting, fundraising, training and other activities.

U.S. officials also expect the agreement to advance talks between the Taliban and the Afghan government and an eventual cease fire that would lead to a full U.S. and NATO withdrawal possibly by the end of next year. They have conceded that thorny questions about a residual U.S. counterterrorism presence remain unresolved. Khalilzad continued negotiations with Afghan and Taliban officials this week, but any agreement will require Trump's final approval.

Bolton's isolation on Afghanistan became particularly apparent this month when the president's top officials descended on Trump's New Jersey golf resort to discuss the peace deal that would be presented to Afghan and Taliban officials in Kabul and Doha, U.S. officials said. In addition to the president, the Aug. 16 meeting included Secretary of Defense Mark Mark Esper chairman of the Joint Chiefs of Staff, Gen. Joseph Dunford Jr. the chairman of the Joint Chiefs of Staff; Vice President Mike Pence, Secretary of State Mike Pompeo, CIA Director Gina Haspel and Khalilzad. Bolton was not originally invited out of concern that his team would oppose the agenda and leak the details later, several officials said.

"His team has a reputation for losing and leaking," said one senior administration official with direct knowledge of the discussions.

Bolton rejected the allegation, saying in a statement, "I categorically deny leaks by me or anyone authorized to speak to the press. Those alleging such leaks should look in the mirror." A senior White House official also disputed the leak claims.

Eventually, Bolton secured a spot at the meeting after one of his aides appealed to White House chief of staff Mick Mulvaney, according to a U.S. official. During the meeting, Bolton and the president exchanged opposing views over policy options on Afghanistan, U.S. officials said. Critics have questioned whether the Taliban can be trusted to fulfill its promises.

Pentagon and State Department leaders are comfortable with the broad outlines of Khalilzad's plan, though maintaining a counterterrorism presence will be critical, officials said. On Wednesday, Dunford stressed that all elements of the deal would be "conditions-based."

The fight over Afghanistan represents just one of several clashes between Bolton and other members of the administration, with several new ones on the horizon.

On Monday, Trump expressed a willingness to a meet with Iran's president, ruled out any plans for regime change in the country and said discussions were underway to see if other nations could extend a "letter of credit" to bolster Iran's ailing economy. Bolton for years has spoken in support of regime change in Iran and has pressed for more sanctions even as the risk of military conflict between the two adversaries grows.

On North Korea, Trump has continued to push for a nuclear deal while downplaying Pyongyang's recurring short-range ballistic missile tests as something "many nations" do. Bolton, whom Trump has kept out of key meetings with North Korean officials, has criticized the tests, underscoring that they violate U.N. Security Council resolutions. An NSC spokesman stressed that Bolton "continues to support the president's position for complete denuclearization of North Korea."

Amid the tensions, Bolton has sought to amplify the diplomatic nature of the national security adviser job, with trips this week to Moldova, Ukraine and Belarus. Despite his differences with Trump, he has found a way to achieve some of his lifelong goals, defunding various United Nations organizations and ripping up international treaties he views as a constraint on American power, such as the Reagan-era Intermediate-Range Nuclear Forces Treaty. He has also had a leading role on Russia policy, holding several meetings with his Russian counterpart Nikolai Patrushev in Moscow and elsewhere.

Defenders of Bolton say while his influence may ebb and flow, he still finds moments to impact policy, such as the president's last-minute decision to walk away from a deal with North Korea in Hanoi. Officials say Bolton opposed the partial denuclearization agreement under discussion.

Bolton's pugnacious views on military force are matched with a fiery temperament. Earlier this year, he got into a confrontation with White House Staff Secretary Derek Lyons in the West Wing, according to people familiar with the incident. The president had signed off on a statement concerning the International Criminal Court, and Bolton didn't want to give Pompeo or other senior White House officials a chance to look at it or make comments, the people said. With Pompeo out of Washington on a trip at the time, the disagreement over the statement's release escalated.

One person familiar said Bolton was merely trying to execute the president's orders. Others said he taunted Lyons, asking him, "Did you have fun today?"

"You better watch out, buddy," Bolton added, the people said.

Trump is expected to make a decision on the path forward on Afghanistan in the coming days as he aims to fulfill a promise of ending America's "endless wars." In the meantime, the decision-making process will continue to test his relationship with his national security adviser.

"Bolton has long said that he's the president's advocate, and his job is to implement his vision," Wright said. "For quite awhile they were compatible, but it now seems to be coming apart."