Kabul, Afghanistan (CNN) Secretary of State John Kerry arrived for an unannounced visit to Afghanistan on Saturday, seeking to diffuse a political crisis in the unity government he helped build.

Kerry urged President Ashraf Ghani and Chief Executive Abdullah Abdullah to set aside their rivalries and work together, warning their political infighting could paralyze the country and dampen the confidence of the international community.

"We need to make certain that the government of national unity is doing everything possible to be unified and to deliver to the people of Afghanistan," Kerry said in an address to the U.S.-Afghanistan Bilateral Commission, which he hosted with his counterpart, Foreign Minister Salahuddin Rabbani.

Their third annual meeting reviewed progress in security, democracy and development outlined in the Strategic Partnership Agreement the two countries signed in 2012.

After a bitterly fought presidential election in 2014, Ghani and Abdullah share power in a national unity government that Kerry helped negotiate.

Kerry's visit comes at a pivotal moment for Afghanistan. Eighteen months into a five-year term, the two rivals have been unable to reconcile their differences and remain deadlocked over key ministries. Several ministers have resigned, others have yet to be confirmed by parliament and still others face losing their jobs over corruption and mismanagement.

Afghan polls show dissatisfaction with the two leaders. A March report by the U.N. said that "for 2016, survival will be an achievement" for the Afghan government, which faces a contracting economy, ongoing Taliban attacks, a stalled peace process, a divided political setting and an ongoing need for international support.

JUST WATCHED Kerry in Baghdad to shore up fight against ISIS Replay More Videos ... MUST WATCH Kerry in Baghdad to shore up fight against ISIS 02:00

Kerry urged the leaders to find compromise ahead of the upcoming NATO summit in Warsaw in July and the Brussels Ministerial Conference on Afghanistan in October in order to give coalition members and donor nations confidence in the government.

"Democracy requires credible institutions. Even more than that it requires the willingness of various political, ethnic and geographic fractions come together and work for common good," Kerry said during a news conference with Ghani.

For his part, Ghani thanked Kerry and the American people for their commitment to Afghanistan. He promised the government would work hard over the coming months to prove to the world their aid and sacrifice in blood and treasure was well spent.

President Barack Obama flagged Afghanistan's problems in October, when he announced he would significantly slow the withdrawal of U.S. troops, leaving 9,800 soldiers in the country through 2016 to train Afghan forces and go after al Qaeda and ISIS.

"After so many years of war, Afghanistan will not be a perfect place," he said. "There will continue to be contested areas and Afghan forces still aren't as strong as they need to be as they face an intensifying Taliban insurgency."

The President called Afghanistan a key part of a counterterrorism network the U.S. uses to deal with threats and prevent attacks on the homeland. Maintaining troop levels to better train Afghan soldiers, he said, is crucial "because if they were to fail, it would endanger the security of us all."

The Afghan government hopes to jumpstart stalled reconciliation talks with the Taliban. The two sides met last summer, but the talks were stymied following the announcement of the death of Taliban leader Mullah Omar.

In December, the U.S., Afghanistan, Pakistan and China joined talks to help facilitate the Afghan-led process, but the Taliban has been unwilling to come back to the table.

With the summer season approaching, it is unclear what incentive the militants have to return to negotiations.

The Taliban has been gaining ground, particularly in Helmand province, where it controls a third of the province's 14 districts. ISIS is also expanding its presence in Afghanistan, as some members of the Taliban have shifted allegiance to the group.

A senior State Department official pointed to "challenges" for the Taliban, including the growing strength of the Afghan forces, the death of Omar and defections by senior commanders to ISIS, which is seeking to expand its presence in the country.

"What this suggests to us is that there may in fact be an opportunity for coming to the table and talking to the Afghan government, and we want to encourage that," the official said.

The official said that despite suffering huge loses and facing several challenges from the Taliban over the last year, Afghan forces have been able to retake the key northern city of Kunduz, hold Helmand and have helped the government maintain government control of Kabul and all the major cities.

"The Taliban ... took their best shot at the Afghan National Security Forces," the official said. "Our belief is that the ANSF has demonstrated a willingness to fight and, indeed, has fought pretty courageously."

Still, the U.S. Special Inspector General for Afghanistan Reconstruction said in a recent report it was unlikely that a "robust and sustainable" force would emerge without a continuing strong U.S. and NATO presence.

Photos: The Taliban Photos: The Taliban The Taliban, a Sunni Islamist organization operating primarily in Afghanistan and Pakistan, was formed in 1994. It was led by Mullah Mohammed Omar, a veteran of the Afghan mujahedeen that fought invading Soviets from 1979-1989. Omar, seen here in an undated video image, died in April 2013 , according to a representative for Afghan President Ashraf Ghani. Hide Caption 1 of 16 Photos: The Taliban In this image taken off television by BBC Newsnight, Omar -- fourth from left -- attends a rally with Taliban troops before their victorious assault on Afghanistan's capital, Kabul, in 1996. The Taliban's aim is to impose its interpretation of Islamic law on Afghanistan and remove foreign influence from the country. Most of its members are Pashtun, the largest ethnic group in Afghanistan. Hide Caption 2 of 16 Photos: The Taliban Tanks manned by Taliban fighters are decorated with flowers in front of the presidential palace in Kabul on September 27, 1996. Hide Caption 3 of 16 Photos: The Taliban Taliban soldiers in Russian-made tanks fire on the forces of former Afghan defense minister Ahmad Shah Massood in October 1996. Hide Caption 4 of 16 Photos: The Taliban Afghan women in Kabul are covered head to toe in traditional burqas on October 16, 1996. After taking over Kabul, the ruling Taliban imposed strict Islamic laws on the Afghan people. Television, music and non-Islamic holidays were banned. Women were not allowed to attend school or work outside the home, and they were forbidden to travel alone. Hide Caption 5 of 16 Photos: The Taliban Three women hitch a ride on the back of a donkey cart as they pass by the ruins of Kabul's former commercial district in November 1996. Hide Caption 6 of 16 Photos: The Taliban This is an undated image believed to show the Taliban's former leader, Mullah Mohammed Omar. In 1997, the Taliban issued an edict renaming Afghanistan the Islamic Emirate of Afghanistan. The country was only officially recognized by three countries: Pakistan, Saudi Arabia and the United Arab Emirates. Hide Caption 7 of 16 Photos: The Taliban In 1997, Omar forged a relationship with al Qaeda leader Osama bin Laden, pictured. Bin Laden then moved his base of operations to Kandahar, Afghanistan. Hide Caption 8 of 16 Photos: The Taliban In March 2001, Taliban soldiers stand at the base of the mountain alcove where a Buddha statue once stood 170 feet high in Bamiyan, Afghanistan. The Taliban destroyed two 1,500-year-old Buddha figures in the town, saying they were idols that violated Islam. Hide Caption 9 of 16 Photos: The Taliban After the 9/11 attacks, the United States conducted military strikes against al Qaeda training camps and military installations of the Taliban regime. In this long-exposure photo, a U.S. Navy fighter jet takes off from the deck of the USS Enterprise on October 7, 2001. Hide Caption 10 of 16 Photos: The Taliban An Afghan anti-Taliban fighter pops up from his tank to spot a U.S. warplane bombing al Qaeda fighters in the Tora Bora region of Afghanistan on December 10, 2001. After massive U.S. bombardment as a part of Operation Enduring Freedom, the Taliban lost Afghanistan to U.S. and Northern Alliance forces. Hide Caption 11 of 16 Photos: The Taliban Afghans look into Omar's bedroom as they go through his compound on the outskirts of Kandahar on December 11, 2001. Hide Caption 12 of 16 Photos: The Taliban In April 2011, hundreds of prisoners escaped from a prison in Kandahar by crawling through a tunnel. The Taliban took responsibility for the escape. This picture shows a general view of the prison, top center, and the house, bottom right, from which Taliban militiamen dug the tunnel leading to the prison. Hide Caption 13 of 16 Photos: The Taliban Security guards stand outside the new Taliban political office in Doha, Qatar, before its official opening in June 2013. The Taliban announced that they hoped to improve relations with other countries, head toward a peaceful solution to the Afghanistan occupation and establish an independent Islamic system in the country. Hide Caption 14 of 16 Photos: The Taliban Zafar Hashemi, deputy spokesman for Afghan President Ashraf Ghani, speaks during a news conference on July 29, when the news of Omar's death was announced. Hide Caption 15 of 16 Photos: The Taliban Mullah Akhtar Mohammad Mansour became the leader of the Taliban after Omar's death. Mansour was killed in an airstrike in Pakistan on Saturday, May 21, 2016 Hide Caption 16 of 16

While in Kabul, Kerry met with Gen. John Nicholson, the new commander of U.S. and NATO forces in Afghanistan who is currently reviewing troop levels in Afghanistan. He also greeted U.S. and NATO troops to thank them for their service.

As he was leaving the post, Nicholson's predecessor, Gen. John Campbell, suggested the U.S. may have to leave a larger presence to train and assist Afghan forces, as well as dial up pressure on the Taliban with airstrikes.

Current rules of engagement only allow U.S. commanders to call in airstrikes to protect NATO troops and Afghan forces in imminent danger of being overrun by the Taliban. They can target al Qaeda and ISIS militants but cannot conduct air strikes against the Taliban unless they pose a direct threat to NATO or Afghan forces.

Campbell told reporters that in order to drive the Taliban toward reconciliation, "They need to have more pressure put on them and one way to do that would be potentially striking them."

James Cunningham, the former U.S. ambassador to Afghanistan, said that while Obama made the right decision to keep the additional troops in Afghanistan, imposing a timetable for their withdrawal sent the wrong signal to both the Afghan forces and the Taliban.

"They need to know someone has their back," Cunningham argued. "They are going to continue to face a serious challenge from the Taliban, who have not been convinced we are going to stay in a meaningful way. They are continuing to wait us out."

On Friday, Kerry confronted similar political and security challenges in Iraq, where the country's prime minister is facing a political crisis that could unseat him. After talks with Prime Minsiter Haider al-Abadi and other Iraqi officials, Kerry stressed the importance of having a "unified and functioning government" to defeat ISIS.