About an hour after the attack another blast also claimed by the Taliban rocked central Kabul near the US embassy, although it was not immediately clear if it claimed any lives.
The explosions come after US President Donald Trump last week abruptly ended talks with the Taliban seeking a deal that would have allowed the US to begin withdrawing troops from its longest war.
The bomber near Ghani's rally -- in Parwan province about an hour's drive north of Kabul -- had been on a motorbike and had detonated his device at checkpoint leading to the event, according to interior ministry spokesman Nasrat Rahimi.
Women and children were among the causalities, Parwan hospital director Abdul Qasim Sangin told AFP, adding 32 people were injured as well as the 24 dead.
The president was unhurt.
In a statement sent to media claiming responsibility for both blasts, Taliban spokesman Zabihullah Mujahid said the attack near Ghani's rally was deliberately aimed at disrupting the September 28 elections
"We already warned people not to attend election rallies, if they suffer any losses that is their own responsibility," the statement said.
Trump's declaration that the talks were "dead" spurred the Taliban to declare last week that the only other option was more fighting.
"We had two ways to end occupation in Afghanistan, one was jihad and fighting, the other was talks and negotiations," Mujahid told AFP last week.
"If Trump wants to stop talks, we will take the first way and they will soon regret it."
The elections will see Ghani face off against his own Chief Executive, Abdullah Abdullah, and more than a dozen other candidates, including former warlords, ex-spies, and onetime members of the country's former communist regime.
For weeks the election had been sideline by the US-Taliban talks, with many Afghans and observers expecting the vote to be cancelled if a deal was agreed. Even candidates did little in the way of campaigning.
But with the deal off, Ghani and his rivals have begun campaigning.
Ghani is seeking a clear mandate they can use to negotiate with the insurgents on a lasting peace in Afghanistan.
Observers had warned the Taliban, who hope to weaken the future president, will do anything they can to upend the election.
On the first day of campaigning in July suicide attackers and gunmen targeted the Kabul office of Ghani's running mate, Amrullah Saleh. At least 20 people died in those attacks.
Turnout in the elections is set to be low, with experts citing fear of violence and a loss of hope among voters following widespread fraud allegations during the 2014 election.