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.
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.
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.