Open this photo in gallery U.S. President Donald Trump eats dinner with U.S. troops at Bagram Air Base, in Afghanistan, on Nov. 28, 2019. TOM BRENNER/Reuters

U.S. President Donald Trump paid a surprise Thanksgiving visit to Afghanistan, where he announced the U.S. and Taliban have been engaged in ongoing peace talks and said he believes the Taliban want a ceasefire.

Trump arrived at Bagram Air Field shortly after 8:30 p.m. local time Thursday and spent 3 1/2 hours on the ground during his first trip to the site of America’s longest war. He served turkey and thanked the troops, delivered a speech and sat down with Afghan President Ashraf Ghani before leaving just after midnight.

As per tradition, reporters were under strict instructions to keep the trip a secret to ensure the president’s safety in the country. About 12,000 U.S. forces remain in Afghanistan.

Story continues below advertisement

Travelling with Republican Sen. John Barrasso of Wyoming and a small clutch of aides, including his acting chief of staff, press secretary and national security adviser, Trump appeared in good spirits as he was escorted around the base by heavily armed soldiers, as the smell of burning fuel and garbage wafted through the chilly air. Unlike last year’s post-Christmas visit to Iraq – his first to an active combat zone – first lady Melania Trump did not make the trip.

Trump’s first stop was a dining hall, where the crowd erupted into cheers when he arrived. There, he served turkey to soldiers dressed in fatigues and sat down for a meal. But he said he only tasted the mashed potatoes before he was pulled away for photos.

“I never got the turkey,” he told the troops. “A gorgeous piece of turkey.”

During his visit, Trump announced that the U.S. and Taliban have been engaged in peace talks and insisted the Taliban want to make a deal after heavy U.S. fire in recent months.

“We’re meeting with them,” he said. “And we’re saying it has to be a ceasefire. And they don’t want to do a ceasefire, but now they do want to do a ceasefire, I believe … and we’ll see what happens.”

The trip came after Trump abruptly broke off peace talks with the Taliban in September, cancelling a secret meeting with Taliban and Afghan leaders at the Camp David presidential retreat after a particularly deadly spate of violence, capped by a bombing in Kabul that killed 12 people, including an American soldier.

That ended a nearly year-long effort by the U.S. to reach a political settlement with the Taliban, the group that protected al-Qaida extremists in Afghanistan, prompting U.S. military action after the Sept. 11, 2001, terrorist attacks. U.S. and international forces have been on the ground ever since.

Story continues below advertisement

It was not immediately clear how long or substantive the U.S. reengagement with the Taliban has been.

Trump ran his 2016 campaign promising to end the nation’s “endless wars” and has been pushing to withdraw troops from Afghanistan and in the Middle East despite protests from top U.S. officials, Trump’s Republican allies in Washington and many U.S. allies abroad. For months now, he has described American forces as “policemen” and argued that other countries’ wars should be theirs to wage.

Tens of thousands of Afghan civilians and more than 2,400 American service members have been killed since the war began 18 years ago.

Just last week, Trump flew to Dover Air Force Base in Delaware to oversee the transfer of the remains of two Army officers killed when their helicopter crashed as they provided security for troops on the ground in Logar province in eastern Afghanistan. The Taliban still controls or holds sway over about half of the country, staging near daily attacks targeting Afghan forces and government officials.

The U.S. and Taliban had been close to an agreement in September that might have enabled a U.S. troop withdrawal.

Nonetheless, Trump said Thursday that he was proceeding with a plan to reduce U.S. troop levels to about 8,600, telling reporters we’re “bringing down the number of troops substantially.”

Story continues below advertisement

Still, he said, the U.S. will stay in the country “until we have a deal or we have total victory.”

Trump made the announcement as he met with Ghani, the Afghan president. Ghani thanked the Americans who have made the “ultimate sacrifice” in Afghanistan and assured the president that Afghan security forces are increasingly leading the fight.

“In the next three months, it’s going to be all Afghanistan!” Ghani said.

Ghani also praised Trump for the October mission that killed Islamic State leader Abu Bakr al-Baghdadi. The Afghan leader also indicated, as Trump himself has, that the al-Baghdadi mission was even more significant than the 2011 mission targeting al-Qaida founder Osama bin Laden. The bin Laden mission was ordered by then-President Barack Obama.

“President Trump, people talked a lot about bin Laden, but what you did to eliminate al-Baghdadi, who was an organizer and not a talker, is a much greater accomplishment,” said Ghani, in remarks to U.S. troops before Trump’s departure.

The trip came a week after the Taliban freed an American and an Australian who had been held hostage since 2016 in exchange for three top Taliban figures – a move that has been widely seen as a possible entree to rekindling peace talks.

Story continues below advertisement

The White House took pains to keep the trip a secret after Trump’s cover was blown last year when Air Force One was spotted en route to Iraq by an amateur British flight watcher.

Cellphones and other transmitting devices were confiscated for most of the trip from everyone travelling aboard Air Force One. And Thanksgiving-themed tweets were teed up to publish ahead of time from Trump’s account to prevent suspicions arising about the president’s silence.

A small group of reporters was told to meet Wednesday night on the top floor of a parking garage in Maryland and was transported in black vans to Andrews Air Force Base. Nobody would confirm where he was going. The only guidance: Dress casually and warmly. Meanwhile, the president was secretly flying back from Florida, where reporters had been told he’d be spending Thanksgiving at his Mar-a-Lago club.

The plane he’d flown to Florida – the modified 747 painted in the iconic white and blue of Air Force One – remained parked on the tarmac at West Palm Beach Airport to avoid revealing the president’s movement.

About 9:45 p.m. Wednesday, the president boarded a nearly identical plane concealed in a hangar at Andrews Air Force Base, taking off and landing under the cover of darkness, with cabin lights dimmed and window shutters drawn.

White House press secretary Stephanie Grisham said plans for the visit had been in the works for weeks.

Story continues below advertisement

“It’s a dangerous area and he wants to support the troops,” Grisham told reporters before Trump landed. “He and Mrs. Trump recognize that there’s a lot of people who are away from their families during the holidays, and we thought it’d be a nice surprise.”

Shortly after midnight, Trump and his entourage departed from Afghanistan.

The president told the troops he was honoured to spend part of his holiday with them.

“There is nowhere I’d rather celebrate this Thanksgiving than right here with the toughest, strongest, best and bravest warriors on the face of the earth,” Trump said.

Our Morning Update and Evening Update newsletters are written by Globe editors, giving you a concise summary of the day’s most important headlines. Sign up today.