(CNN) -- U.S. Secretary of State John Kerry made a previously unannounced visit to Afghanistan on Monday to repair strained relations with President Hamid Karzai as the American-led international force continues to prepare to end its combat mission next year.
Kerry's stop came on the same day that U.S. forces turned over control of a prison that has caused tension between the two nations, with Americans retaining a say on the handling of certain Taliban inmates.
The talks on Monday followed controversial comments by Karzai in recent weeks that seemed to accuse U.S. forces of working with the Taliban to kill Afghan civilians, a charge denied by U.S. officials.
Karzai's reported remarks caused outrage in Washington with some in Congress questioning why the United States should continue the war effort.
At a joint news conference after meeting Kerry, Karzai said he had been misinterpreted when quoted as alleging collusion between the Americans and the Taliban.
But he made clear that violence against villagers must stop for there to be any chance for successful peace talks.
Karzai explained that he was talking about Taliban violence, especially how a bombing in Kabul that killed nine people didn't help achieve the Taliban goal of getting foreign troops to withdraw. He said media reports misinterpreted his comments to mean he was accusing the Taliban and United States of collusion.
"If they want the international community to leave Afghanistan, then the best way is for them to stop killing people," Karzai said of the Taliban. "That does not mean a collusion between the Untied States and Taliban. That's a conclusion the press came up with."
Karzai also said some U.S. special forces in Wardak province had tortured and killed Afghan civilians, but that had stopped when those forces were removed under a recent agreement after his government complained.
He made sure to emphasize his appreciation for U.S. support, twice declaring the thanks of the Afghan people for American assistance that he said would "enable Afghanistan to manage itself through 2014 and beyond."
For his part, Kerry emphasized the commitment of President Barack Obama to Afghanistan and its people would continue past the halt in combat operations by the NATO forces before the end of next year.
The United States and Afghanistan are negotiating an agreement that would allow some U.S. forces to remain in Afghanistan beyond the end of the NATO mission, but unresolved issues include how many and there specific role.
Kerry said Obama "was committed to not allow America's investment and the sacrifice here to be reversed," adding that "the United States will still be playing a role and will be here through the course of this future period."
Meanwhile, the former commander of the international military force in Afghanistan, U.S. Gen. John Allen, said Monday that the war there would continue after foreign troops conclude their combat mission by the end of 2014.
"On the first of January, there's still going to be fighting in 2015. There's still going to be fighting in Afghanistan," Allen told a conference at the Brookings Institution.
He added that Afghanistan would "join a long and distinguished list of countries that will be struggling in a post-conflict environment where it will have an insurgency in some parts of that country for an extended period of time."
Kerry landed in Kabul on Monday afternoon and met with Karzai at the presidential palace before the news conference that lasted almost an hour. The two were to talk further over dinner and perhaps again on Tuesday morning, Kerry said.
Earlier Monday, the United States handed over control of a U.S.-run prison near Bagram Air Base to Afghan authorities.
Karzai called the development a major boost for the transition, while Kerry emphasized several times that the agreement respected Afghanistan's sovereignty to operate the prison that holds Taliban figures.
The agreement includes provisions to give the United States a say on how some of the most notorious Taliban prisoners are handled. Karzai outlined a process in which U.S. officials provide intelligence to Afghan officials on specific prisoners, and further consultations follow if the Afghans want to set them free.
In a sign of the sensitivity of the issue, Karzai twice described the final step of the process as consultations, then changed his wording to "an exchange of views." He said that "I must use my words carefully."
"We will consider it," he said of a U.S. request to keep particular prisoners in custody, adding that Afghan law would call for such handling of anyone posing a legitimate threat.
The matter touches on a politically charged situation for Karzai, who is criticized by the Taliban and other foes for the continuing presence of the NATO forces in the country.
The handover deal was reached Saturday, but came a full year after the initial plan was announced by U.S and Afghan authorities.
An initial plan called for the prison and detainees to be handed over within six months, but in September, the United States "paused" the transfer of detainees, which include suspected Taliban militants and insurgents.
Other tensions between the countries involve continuing violence, such as a bomb blast in Kabul this month that killed nine people. Karzai said afterward that there are "ongoing daily talks between the Taliban, Americans and foreigners in Europe and in the Gulf states."
The comment effectively claimed the United States was trying to foment continued violence inside Afghanistan, and it was quickly denounced by NATO and U.S. officials.
Some experts say Karzai's comments were fueled by frustration over the detention facility not being handed over sooner, which he viewed as an attack on his country's sovereignty.
During the news conference, Kerry repeatedly referred to Afghanistan's sovereignty in the transition process as the NATO military force turns over leadership of combat operations to Afghanistan's military, which it has trained in recent years.
Under an agreement between the Afghan government and NATO, the bulk of U.S. and NATO combat forces are to be out of Afghanistan by the end of 2014. What remains to be decided is how many troops may remain to help train Afghan forces.
The trip was Kerry's first visit to Afghanistan as secretary of state, but the former senator's sixth during Obama's presidency.
He was in Iraq over the weekend to press that nation's leaders to take steps prohibiting Iranian planes from delivering arms to Syria's besieged government. Last week, Kerry joined Obama on a trip to Israel, the Palestinian territories and Jordan.
CNN's Nick Paton Walsh, Barbara Starr, Chelsea J. Carter and Ed Payne contributed to this report.