The group directed its fighters to stop all offensive operations during the holiday, although it said they would defend themselves if attacked.
"The Government of the Islamic Republic of Afghanistan announces a ceasefire from the 27th of Ramadan until the fifth day of Eid-ul-Fitr following the historic ruling (Fatwa) of the Afghan Ulema", he added.
The Taliban added that "foreign occupiers are the exception" to the order sent to its fighters.
Ghani's surprise declaration came on the heels of a fatwa issued by Afghanistan's top clerics forbidding suicide attacks and a Pentagon announcement that senior Taliban officials had been negotiating with Afghan authorities on a possible ceasefire.
An hour after the fatwa was issued, a suicide bomber detonated outside the gathering, killing seven people.
The US and North Atlantic Treaty Organisation formally concluded their combat mission in Afghanistan in 2014, but the US still has thousands of forces based there in a support and counterterrorism role.
Four people were killed and five wounded by unidentified gunmen in a separate attack on a lawmaker's Nangarhar home on Friday.
Their announcement comes days after the Afghan government declared aunilateral eight-day cease-fire and for the first time promises Afghan civilians, who have borne the brunt of the 17-year conflict, a temporary reduction in violence, which has only been spiraling in recent years.
The Taliban has been fighting in Kabul since it was removed from power in 2001 by the US-led forces.
Ghani has urged ceasefires with the Taliban before, but this was the first unconditional offer since he was elected in 2014.
The United States intends to step up military operations against the militant Islamic State group in eastern Afghanistan during a temporary ceasefire between the Afghan government and the Taliban, senior U.S. officials said on Friday.The Islamic State group has developed a stronghold in Nangarhar, on the porous eastern border with Pakistan and is among the countrys most unsafe militants since it appeared around 2015. The armed group has set the withdrawal of foreign forces as a pre-condition for peace talks.