Cameron arrived in Kabul on the unannounced visit after visiting an air base in Cyprus, where British jets launching strikes against Islamic State militants in Iraq are based.
Ghani was sworn in on Monday after a fraud-tainted election that plunged Afghanistan into months of political deadlock.
In a US-brokered deal, Ghani signed a power-sharing agreement with his former poll rival Abdullah Abdullah, who was appointed to the new position of "chief executive".
The presidential palace in Kabul and British officials confirmed that the visit had started, and talks were under way.
The British army has wound down its presence in the volatile southern Afghan province of Helmand after years of heavy fighting in some areas where the Taliban has launched fresh offensives in recent weeks.
Britain still has 3,900 troops in the country as part of the NATO's International Security Assistance Force (ISAF), most of them at Camp Bastion in Kandahar province.
The British contribution to the follow-up mission will be at an army officers' training academy outside Kabul.
On Tuesday, his first full day in office, Ghani signed separate agreements with the US and NATO permitting foreign troops to stay in the country into next year.
The agreements had been delayed for more than a year as then-president Hamid Karzai refused to sign them despite domestic and international pressure.
The new US-led mission, which will take over on January 1, will be made up of 9,800 US troops and about 3,000 soldiers from other coalition member nations.
Afghan casualties have rocketed over the past two years as NATO has scaled back and handed over most combat duties to the Afghan police and army.
General John Campbell, who recently took over as head of ISAF, said yesterday that 7,000 to 9,000 Afghan soldiers and police had been killed or wounded already in 2014.
