During his meeting with Ghani, both the leaders pledged support to each other in their fight against terrorism and vowed to restrict the use of their soil against each other, said an ISPR statement.
Both countries also agreed to continue the ongoing operation against militants in their respective countries, the statement added.
General Raheel also met with Afghan CEO Dr Abdullah Abdullah who acknowledged the overall positive trajectory in bilateral relations. Abdullah also talked about progress in border management and intelligence sharing.
Earlier, General Raheel along with Director General Inter-Services Intelligence (ISI) Lieutenant General Rizwan Akhtar arrived in Kabul on a one-day official visit.
During their stay in Kabul, the army chief and DG ISI met the Afghan civil and political leadership, a statement issued by ISPR said.
AFP adds: Army chief General Raheel Sharif held talks in Kabul Tuesday with Afghanistan President Ashraf Ghani on boosting security and continuing operations against Taliban militants, the military said.
The two praised improved relations and pledged that they would not provide a safe haven for militants from each other's countries to use to launch attacks, chief army spokesman Major General Asim Bajwa said in a Twitter message.
Pakistan accuses Afghanistan of protecting members of the Pakistani Taliban, while Afghanistan routinely accuses neighbouring Pakistan of providing shelter within its borders to the Afghan Taliban.
Ghani, who came to power in September, and Pakistani Prime Minister Nawaz Sharif have overseen an improvement in ties in recent months.
General Sharif also visited Kabul in December of last year, immediately after an attack on an army-run school in Peshawar where Taliban militants killed more than 150 people, most of them children.
The general is hailed for stepping up operations against militants and engaging with United States, China, Saudi Arabia, Afghanistan and other countries to bolster the fight against terrorism. Pakistan's army and intelligence services are widely seen as the driving force behind the country's defence and foreign policies.
Sharif also held talks with Abdullah Abdullah, who holds the number two role of chief executive in the Afghan government, and "who acknowledged overall positive trajectory in bilateral relations, concrete progress in operations, border management and intelligence sharing", Bajwa said.