BAGRAM AIR BASE, Afghanistan — U.S. Secretary of State Rex Tillerson said Monday there is a place for moderate elements of the Taliban in Afghanistan’s government as long as they renounce violence and terrorism and commit to stability. He also delivered a blunt warning to neighboring Pakistan, insisting Islamabad must step up action against terrorist groups that have found safe haven within its borders.

Speaking on an unannounced trip to Afghanistan where he met Afghan President Ashraf Ghani, Chief Executive Abdullah Abdullah and other senior officials at Bagram Air Base north of Kabul, Tillerson said the Taliban must understand that they will never win a military victory and should prepare to negotiate with the government.

“Clearly, we have to continue to fight against the Taliban, against others, in order for them to understand they will never win a military victory,” Tillerson told a small group of reporters allowed to accompany him from the Qatari capital of Doha. “And there are, we believe, moderate voices among the Taliban, voices that do not want to continue to fight forever. They don’t want their children to fight forever. So we are looking to engage with those voices and have them engage in a reconciliation process leading to a peace process and their full involvement and participation in the government.”

“There’s a place for them in the government if they are ready to come, renouncing terrorism, renouncing violence and being committed to a stable prosperous Afghanistan,” Tillerson said.

Tillerson outlined to Ghani and Abdullah the Trump administration’s new South Asia policy, which the president rolled out last month and views the region through a lens that includes Afghanistan as well as Pakistan and India, both of which he will visit later this week. The approach is heavy on combatting and beating extremist groups in all three countries.

“We also want to work with regional partners to ensure that there are no threats in the region,” he said. “This is very much a regional effort as you saw. It was rolled out in the strategy itself, demanding that others deny safe haven to terrorists anywhere in the region. We are working closely with Pakistan as well.”

Tillerson will visit Islamabad on Tuesday and said he would be telling Pakistani officials that their cooperation in fighting extremists and driving them from hideouts on their territory is imperative to a good relationship with the U.S.

“It will be based upon whether they take action that we feel is necessary to move the process forward for both creating opportunity for reconciliation and peace in Afghanistan but also ensuring a stable future Pakistan,” he said. “Pakistan needs to, I think, take a clear-eyed view of the situation that they are confronted with in terms of the number of terrorist organizations that find safe haven inside of Pakistan. So we want to work closely Pakistan to create a more stable and secure Pakistan as well.”

The administration’s strategy for South Asia envisions it as part of what Tillerson referred to in a speech last week as Indian-Pacific Ocean platform, anchored by four democracies: India, Australia, Japan and the United States. The U.S. is placing high hopes on India’s contributions in South Asia, especially in Afghanistan where Tillerson said New Delhi could have significant influence and presence by creating jobs and “the right environment for the future of Afghanistan.”

Tillerson also met at Bagram with senior members of the U.S. military contingent, including Army Gen. John Nicholson, the top U.S. commander in Afghanistan. He underscored the ongoing U.S. commitment to stabilizing Afghanistan but stressed it is “conditions based,” meaning that the government must meet certain benchmarks. He praised Ghani for his efforts to curb corruption and prepare for the country parliamentary elections next year.

“It is imperative in the end that we are denying safe haven to any terrorist organizations or any extremists to any part of this world,” Tillerson said.

He arrived in Afghanistan cloaked in secrecy and under heavy security. He had slipped out of Qatar in the pre-dawn hours and flew a gray C-17 military plane to Bagram, jettisoning his public schedule, which had him meeting with staffers at the U.S. Embassy in Doha.

Tillerson, a one-time private pilot, rode in the cockpit wearing a headset and chatting with the crew as the plane took off from the Al-Udeid Air Base outside Doha.