KABUL — Defense Secretary Jim Mattis visited Afghanistan on Tuesday to meet senior U.S. and Afghan officials and discuss both the military campaign and “peeling off” some members of the Taliban to pursue a peace deal with the Afghan government.

The unannounced visit comes two weeks after Afghan President Ashraf Ghani made what many observers consider an unprecedented offer, inviting the Taliban to begin peace talks without preconditions to end the 16-year war. The Taliban said last month that it is open to reaching a political settlement and negotiating, but it has not responded to Ghani’s offer.

Mattis, speaking on a flight to Afghanistan from Oman, said that talking about a peace settlement is “not cart before the horse” and that it is backed by the ongoing efforts of the U.S. and Afghan militaries. Some members of the Taliban may be willing to pursue peace, especially considering a fracturing in the group that has occurred over the past few years, he said.

“All wars come to an end,” Mattis said. “You don’t want to miss an opportunity because you weren’t alert to the opportunity. So, you need to have that door open, even if you embrace the military pressure.”

Mattis acknowledged that efforts to reconcile with the entire Taliban have been difficult. The effort right now, he said, is to reach “those who are tired of fighting” and build it out from there.

Army Brig. Gen. Michael R. Fenzel, a senior U.S. military planning officer, said Tuesday that the fact that the Taliban hasn’t already dismissed meeting with the Afghan government about negotiations already may be a positive sign. Typically, the group dismisses conversations like that out of hand, Fenzel said.

The general said that the U.S.-led military coalition has seen “significant evidence across the entire country that there is interest” in reconciliation, with groups of 10 and 20 Taliban fighters at a time turning themselves in. He acknowledged, however, that their doing so has not yet “reached critical mass.”

The defense secretary and his staff arrived at Kabul’s Hamid Karzai International Airport on a C-17 jet in the morning before being whisked away on a CH-47 Chinook helicopter in damp, chilly weather to the U.S. military headquarters in Kabul. He met immediately with senior officials, including U.S. Ambassador to Afghanistan John Bass and Army Gen. John W. Nicholson Jr., the top U.S. officer in Afghanistan. Afterward, he visited with Ghani and other senior Afghan officials at the Presidential Palace.

Ghani said at the palace that President Trump’s new South Asia strategy, adopted in August, allows Afghan officials to tell their people that talking about peace with the Taliban “is not tantamount to surrender or to collapse.” The strategy calls for ramping up military and diplomatic pressure on the Taliban to force a negotiated settlement, and does not include a timetable for U.S. military withdrawal, a notable difference to the plan under President Barack Obama.

Ghani noted that an offer of peace in the 1990s ultimately led to the collapse of the Afghan government, “and people always carry their memories.”

Mattis visited the country for the second time Tuesday since the new strategy was unveiled. The Pentagon chief is among a small group of senior advisers who convinced Trump that it made sense to not only continue the U.S. role in the war but also bolster it with more air power and a modest increase in the number of U.S. troops from about 11,000 to 14,500.

But the Taliban remain a powerful force in Afghanistan, regularly carrying out high-profile attacks in and around Kabul in addition to holding or contesting more than a quarter of Afghanistan’s territory.

The defense secretary’s latest visit included a new security precaution in which journalists traveling with him were directed to withhold publishing anything until after he left the airport and arrived at the U.S. military headquarters in Kabul. That followed a Taliban attack on the airport in September a few hours after Mattis’s last visit. The attack prompted a U.S. response that led to civilian casualties when an American jet dropped a malfunctioning missile on a nearby home.

Trump, in announcing his plan, said that it was his initial instinct to pull out U.S. troops — an apparent acknowledgment of how unpopular the war is with the American public after more than 2,200 U.S. military fatalities and more than $1 trillion in taxpayer spending. Senior U.S. officers, including Nicholson, have said that the U.S. military has reached a turning point in Afghanistan this year, but similar points have been made in the past.

In the past few months, the air campaign has ramped up, with hundreds of Air Force strikes each month since August and 4,361 in total last year. That’s up from a total of 1,337 in all of 2016. The Pentagon also has started to deploy additional U.S. military advisers to fan out across the countryside with Afghan troops. They are expected to coordinate air power, fire support and intelligence collection and analysis, skills with which the Afghan military and police forces have often struggled.

The beefed-up military action follows two years of the Afghan government struggling to maintain control of its territory, including numerous areas where American forces fought the Taliban and suffered fatalities. As of October, the government in Kabul had control or influence in 56 percent of its 407 districts. Insurgents controlled 14 percent, with another 30 percent contested. That marked a drop from fall 2016, when the government controlled 72 percent, with 7 percent under insurgent control and 21 percent contested.

This story was originally published at 2:27 a.m. East Coast time and updated multiple times with additional reporting from Afghanistan.

This story has been corrected to reflect that the U.S. military is tracking 407 districts in Afghanistan.