The resignation of Rahmatullah Nabil comes as Afghanistan grapples with string of major Taliban attacks, including a 27-hour siege of Kandahar airport this week which killed at least 50 people.
Eleven Taliban suicide attackers on Tuesday breached the high-security Kandahar air field, which also houses a joint NATO-Afghan base, taking families hostage and triggering pitched firefights with soldiers.
In his resignation letter, Nabil citied "a lack of agreement on policy matters" and restrictions imposed by the president which he alleged had hindered his ability to do his job.
"Our innocent countrymen were being martyred and beheaded in Kandahar airfield... At the moment when (Pakistan) Prime Minister Nawaz Sharif once again called Afghanistan as Pakistan's enemy," he wrote.
Also Read
The office of the president was not immediately reachable for comment.
Ghani's willingness to visit Afghanistan's longtime nemesis signalled a renewed push to mend badly frayed cross-border ties, which could help jumpstart long-stalled peace talks with the insurgents.
Pakistan, which wields considerable influence over the Taliban, hosted a milestone first round of peace negotiations in July.
Ties between Ghani and Nabil have been strained since the Taliban's three-day capture of northern Kunduz city in September, which marked their biggest success in 14 years of war.
His resignation comes as a setback for Afghanistan's security establishment, already without a permanent defence minister and struggling to rein in the ascendant insurgency.