Defense Secretary Jim Mattis made a surprise visit to Kabul on Friday and held talks with Afghan government leaders on a peace process with Taliban insurgents and the country’s spiraling violence.

Arriving in a capital gripped by security jitters and political uncertainty ahead of parliamentary elections scheduled for next month, Mattis met with President Ashraf Ghani and Chief Executive Abdullah Abdullah, the presidential palace said. Also among the topics, it said, were Afghanistan’s relations with neighboring Pakistan, which Kabul has long accused of harboring militants who carry out attacks on Afghan and U.S. troops.

Joining Mattis was Marine Gen. Joseph F. Dunford Jr., chairman of the Joint Chiefs of Staff. Their visit to Afghanistan lasted a little more than six hours and included a meeting with Army Gen. Austin S. Miller, who took over as commander of U.S. and NATO forces in the country Sunday.

Earlier this week, Dunford traveled to Islamabad with Secretary of State Mike Pompeo in an effort to “reset the relationship” with Pakistan’s new government after a period of sharp disagreements.

Washington has suspended at least $900 million in military aid to Pakistan this year, accusing it of failing to rein in militants on its soil and pressure their leaders to accept face-to-face talks with the Afghan government.

From right, Afghan President Ashraf Ghani meets with Defense Secretary Jim Mattis, U.S. Ambassador to Afghanistan John Bass and Gen. Joseph F. Dunford Jr., chairman of the Joint Chiefs of Staff, at the Presidential Palace in Kabul on Friday. (Thomas Watkins/AFP/Getty Images)

At Friday’s meeting, “they discussed the peace process, the positive impact of the South Asia strategy, reforms in the Afghan National Defense and Security Forces, the upcoming elections, counterterrorism and dialogue with Pakistan,” said Haroon Chakhansuri, a spokesman for Ghani.

Mattis did not speak with reporters about the meeting, which came after months of heightened concern among Afghans about deteriorating security. Attacks by Taliban insurgents and Islamic State affiliates in recent weeks have left hundreds of Afghan security personnel and civilians dead, with government and U.S.-led troops seemingly unable to stop them.

Before arriving in Kabul, Mattis told reporters he is hopeful about the prospect of peace talks with the Taliban.

“Right now, we have more indications that reconciliation is no longer just a shimmer out there, no longer just a mirage,” Mattis said, news agencies reported.

“It now has some framework. There’s some open lines of communication,” he added.

In July, a top State Department official met Taliban officials in Qatar as part of a U.S. effort to promote peace talks. The Afghan war, America’s longest, began 17 years ago when Afghan resistance forces and U.S. airstrikes drove the Taliban from power in Kabul after the Sept. 11, 2001, terrorist attacks. Including periods of Soviet occupation and civil war involving various factions, Afghanistan has been wracked by fighting for most of the past four decades.

The United States views the Taliban’s acceptance of a temporary truce in June as grounds for optimism.

“The most important work that has to be done is beginning the political process and reconciliation,” Dunford told reporters traveling with him.

“What we are trying to do in the military dimension is convince the Taliban that they cannot win on the battlefield and that they must engage in a peace process,” he said.