WASHINGTON — President Donald Trump reluctantly agreed in a meeting with his national security team Tuesday to keep U.S. troops in Syria for an undetermined period of time to defeat ISIS, but pressured them to end U.S. involvement in the conflict as soon as possible, a senior administration official said Wednesday.

The official described Trump as frustrated and exasperated with the situation and the answers he was getting from his team.

"He wasn’t thrilled about it, to say the least," the official said.

Defense Secretary James Mattis and other top officials made the case to Trump that the fight against ISIS was almost finished but a complete withdrawal of U.S. forces at this time would risk losing gains the U.S. has made in the fight, the official said.

Mattis told the president the Pentagon was already reducing the number of U.S. forces and would continue to do so. When his advisers told him they needed more time to complete the mission and secure the gains they’ve made, Trump demanded to know how much longer, the senior administration official said.

"If you need more time, how much more time do you need? Six months? A year?" he asked, according to the official.

His team said they couldn't put a time frame to how long it will take to defeat remaining ISIS forces and train local forces to maintain their gains after the U.S. leaves.

The official said Trump "wasn’t thrilled about that either," but agreed to give the effort more time when advisers reminded him that he has criticized setting arbitrary deadlines in military operations, particularly withdrawal, in the past.

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

"The president made his displeasure clear about any kind of long-term presence in Syria," the official said, adding that Trump was trying "light a fire" under his team to get the military mission wrapped up.

Joseph Dunford, the chairman of the joint chiefs of staff, and John Sullivan, the acting U.S. secretary of state, were in the meeting, which took place Tuesday after Trump's comments on Syria at a joint press conference with the Baltic heads of state, along with Mattis. John Bolton, Trump's nominee to replace H.R. McMaster, as national security adviser, was not in attendance, nor was Mike Pompeo, Trump's CIA director and pick to replace Rex Tillerson as secretary of state, according to the official.

The official said Trump told his aides that he expects partner governments in the region to make good on verbal pledges to help pay for reconstruction. In the meeting, according to two U.S. officials, Trump said the Saudis would provide as much as $4 billion in stabilization efforts for Syria.

The U.S. has around 2,000 forces on the ground in Syria fighting ISIS.

Tuesday’s meeting followed a scramble by Trump’s national security aides to address his recent threat to pull out all U.S. forces from Syria.

Earlier Tuesday, Trump said he wanted to get out of Syria and bring U.S. troops back home — only moments after his top advisers said publicly that the fight against ISIS was not finished.

A convoy of U.S. troops drive on a road leading to the tense front line with Turkish-backed fighters in Manbij, north Syria, on Saturday. Hussein Malla / AP

"I want to get back, I want to rebuild our nation," Trump said, reiterating comments about withdrawal that he made last week. "It's time. We were very successful against ISIS; we'll be successful against anybody militarily, but sometimes it's time to come back home. And we're thinking about that very seriously."

The president, speaking at a joint news conference at the White House with the leaders of the Baltic states, did not give a timeline for withdrawing U.S. troops but said a decision would be made soon.

Just minutes earlier, however, the president's envoy to the Global Coalition to Defeat ISIS, Brett McGurk, had stressed that the job was not finished.

"We are in Syria to fight ISIS. That is our mission," McGurk said, standing alongside Army Gen. Joseph Votel, commander of the U.S. Central Command, at the U.S. Institute of Peace. "Our mission is not over. And we are going to complete that mission."

U.S. and coalition partners on the ground have taken control of almost 95 percent of the territory in Syria once held by ISIS, but U.S. officials have said their remaining presence will prove difficult to eliminate quickly and could take months.

Votel, for his part, stressed on Tuesday the importance of stabilization in Syria, and said the U.S. military can help.

"The hard part, I think, is in front of us, and that is stabilizing these areas, consolidating our gains, getting people back into their homes," Votel said.

In a statement Wednesday, the White House said the U.S. mission in Syria was "coming to a rapid end."

"The military mission to eradicate ISIS in Syria is coming to a rapid end, with ISIS being almost completely destroyed. The United States and our partners remain committed to eliminating the small ISIS presence in Syria that our forces have not already eradicated," Press Secretary Sarah Huckabee Sanders said. "We will continue to consult with our allies and friends regarding future plans. We expect countries in the region and beyond, plus the United Nations, to work toward peace and ensure that ISIS never re-emerges."

But Nick Rasmussen, former director of the National Counterterrrorism Center and an MSNBC and NBC News national security and intelligence analyst, said Wednesday that the U.S. should exercise caution in declaring victory over the terrorist group.

"There is still a significant ISIS problem we’re dealing with. When you use words like defeat and destroy, that’s a pretty high bar to get to in terms of eliminating a terrorist organization," Rasmussen said.

Carol E. Lee and Courtney Kube reported from Washington, and Adam Edelman from New York.