Ban's first visit to the country was aimed at "ensuring solid coordination between the U.N. and Afghan government in their joint efforts here," said Adrian Edwards, the U.N. spokesman in Afghanistan.
Along with Karzai, Ban met the head of NATO's International Security Assistance Force, Gen. Dan McNeill, and other officials, Edwards said.
The visit comes ahead of a July 2-3 conference in Rome, which will seek ways of improving the weak justice system in Afghanistan, Edwards said.
Karzai and Ban will preside over the conference along with Italian Foreign Minister Massimo D'Alema, the Italian Foreign Ministry said.
U.S. Assistant Secretary of State Richard Boucher, NATO's Secretary-General Jaap de Hoop Scheffer and Tom Koenigs, the top U.N. official in Afghanistan, will also be among the participants as will some regional players like Pakistan.
Issues on the agenda include access to justice, prison reform and legal training. Organizers say the conference will try to provide tools to improve coordination among law-enforcement officials and tackle corruption.