U.S. Secretary of State John Kerry and Afghan President Hamid Karzai made a show of rare unity between their two nations Monday, as the U.S. military ceded control of its last detention facility in Afghanistan, ending a longstanding irritant in relations.

Kerry arrived in the Afghan capital of Kabul on an unannounced visit amid concerns that Karzai may be jeopardizing progress in the war against extremism with anti-American rhetoric. After a private meeting, Kerry said he and Karzai were “on the same page” on security and reconciliation issues, and brushed aside suggestions that relations were in peril.

Karzai had infuriated U.S. officials by accusing Washington of colluding with Taliban insurgents to keep Afghanistan weak even as the Obama administration pressed ahead with plans to hand off security responsibility to Afghan forces and end NATO’s combat mission by the end of next year.

At a joint news conference after their talks, Karzai told reporters his comments had been misinterpreted by the media. Kerry said officials sometimes make comments in public that reflect an idea that they have heard expressed by others.

“I am confident the president (Karzai) does not believe the U.S. has any interest except to see the Taliban come to the table to make peace and that we are completely cooperative with the government of Afghanistan with respect to the protection of their efforts and their people,” Kerry said. He noted that he had specifically raised the collusion comment with Karzai and was satisfied with what he had heard in response.

“We’re on the same page,” Kerry said. “I don’t think there is any disagreement between us and I am very, very comfortable with the president’s explanation.”

For his part, Karzai said “today was a very good day,” citing the turnover of the detention facility at the U.S.-run Bagram military base north of Kabul. He also expressed gratitude for the sacrifices made for his country by Americans. However, he defended allegations he has made about American troops abusing Afghan civilians, saying they were not meant to “offend” anyone but rather to protect his people.

“When I say something publicly, it is not meant to offend our allies but to correct the situation,” he said. “I am responsible for the protection of the Afghan people. I am the president of this country. It is my job to provide all the protection I can to the people of this country.”

The news conference came near the beginning of Kerry’s 24-hour visit to the country — his sixth since President Barack Obama took office but his first as secretary of state.

He referred frequently to U.S. respect for Afghanistan’s sovereignty and said the handover of the detention facility was testament to that respect.

Earlier Monday, the U.S. military ceded control of the Parwan detention facility near the U.S.-run Bagram military base, a year after the two sides initially agreed on the transfer. Karzai had demanded control of Parwan as a matter of national sovereignty.

The long-running dispute over the center had thrown a pall over ongoing negotiations for a bilateral security agreement to govern the presence of U.S. forces in Afghanistan after 2014.

An initial agreement to hand over Parwan was signed a year ago, but efforts to follow through on it constantly stumbled over American concerns that the Afghan government would release prisoners that it considered dangerous.

The U.S. concerns are not without foundation. Zakir Qayyum, a former Guantanamo detainee, was released into Afghan custody in 2007. Freed four months later, he rejoined the Taliban and reportedly has risen to become the No. 2 leader in the Taliban.