The attacks happened 11 days before Afghanistan's presidential election, which Taliban commanders have vowed to violently disrupt, and follow collapsed peace talks between the United States and the militant group, Reuters wrote.
Ghani, who is seeking a second five-year term in voting on Sept. 28, was due to address a rally in Charikar, the capital of central Parwan province, when a suicide bomber attacked the gathering.
The blast killed 26 people and wounded 42, said Nasrat Rahimi, the spokesman for the Interior Ministry.
"When the people were entering the police camp, an old man riding a motorcycle arrived on the highway and detonated his explosives, causing casualties," said provincial police chief Mohammad Mahfooz Walizada.
In the wake of the attack, bodies littered the dusty ground as smoke rose from the site of the explosion, a giant blue billboard bearing the face of Ghani's running mate Amrullah Saleh looming over the scene.
With sirens wailing, rescuers rushed to lift the wounded into the backs of pick-up trucks for evacuation.
The president was nearby but unharmed, and later took to Twitter to condemn the bombing at the rally.
"Taliban tried to break this unity by targeting innocent civilians," he wrote. "They shamelessly accepted responsibility at a time when they're cloaking acts of terror as efforts for peace."
In a separate incident, a man on foot blew himself up in the center of the capital Kabul, sending ambulances and Afghan forces rushing to the blast site.
"I was waiting at the entrance of the recruitment center," said Mustafa Ghiasi, lying on a hospital bed after being wounded in the explosion. "I was behind two men in line when suddenly the blast struck."
Twenty-two people were killed, and 38 were wounded, said Rahimi, the Interior Ministry spokesman. Most of the dead were civilians, including women and children, though six were security force members.
The Taliban said it carried out the two attacks, and a statement issued by a spokesman for the militants said they were aimed at security forces.
"People were given warning," the statement said.
Addressing the Kabul attack, Afghanistan's president lashed out at the Taliban as the "coward enemy" for targeting civilians.
"I offer my heartfelt condolences to victims of today's tragedies in Kabul and Parwan and pray for speedy recovery of those who were wounded," Ghani wrote on his official Twitter account. "We stand united in this hour of grief."
Pakistan, which denies accusations that it shelters the Taliban, also condemned the attack.
"We offer our heartfelt condolences to the bereaved families," it said in a statement.
Security at rallies across the country has been tight following threats by the Taliban to attack meetings and polling stations. The group has vowed to intensify clashes with Afghan and foreign forces to dissuade people from voting in the upcoming elections.
Last week, peace talks between the United States and the Taliban collapsed. The two sides had been seeking to reach an accord on the withdrawal of thousands of American troops from Afghanistan in exchange for security guarantees from the insurgents.
The negotiations, which did not include the Afghan government, were intended as a prelude to wider peace negotiations to end more than more 40 years of war in Afghanistan.