A suicide bomber has targeted a campaign rally by President Ashraf Ghani in northern Afghanistan, killing at least 24 people and wounding 31, officials said.

Mr Ghani was at the venue but was unharmed, according to his campaign chief.

Hours later, an explosion struck near the US embassy in the capital Kabul but details were not immediately known.

The scene of the suicide attack
The scene of the suicide attack (Rahmat Gul/AP)

The Taliban claimed both attacks, which came as Afghanistan faces presidential elections on September 28. The Taliban have warned that polling stations and election campaigns will be targeted.

In Tuesday’s suicide attack, the bomber rammed a motorcycle packed with explosives into the entrance of the venue where Mr Ghani was campaigning on the outskirts of the city of Charakar in northern Parwan province.

There were many women and children among the casualties, said Dr Qasim Sangin, a local official.

Ashraf Ghani
Ashraf Ghani (Rahmat Gul/AP)

Wahida Shahkar, spokeswoman for Parwan’s governor, said the rally had just begun when the explosion occurred.

Firdaus Faramarz, spokesman for the Kabul police chief, said there was no immediate information about casualties in the blast in the capital, which took place near Massood Square, a congested intersection in the centre of the city.

Nato and US compounds are located nearby as are several Afghan government ministries.

Campaigning for the Afghan elections resumed last week after President Donald Trump declared that US-Taliban talks which have been going on for months in the Gulf Arab state of Qatar were over.

Donald Trump
Donald Trump (Evan Vucci/AP)

Most presidential candidates had suspended their campaigns while negotiations were taking place and as the US peace envoy, Zalmay Khalilzad, said a deal was all but signed.

Mr Trump’s tweets at the beginning of September declaring the deal and the talks were “dead” launched the war-battered nation on an election campaign.

Mr Ghani, who had been sidelined during much of the discussion between Mr Khalilzad and the Taliban, resumed campaigning immediately and had been steadfast in his demand that presidential polls should take place.

Mr Khalilzad and some of Mr Ghani’s rivals had talked of establishing an interim administration to run the country while a peace deal was implemented.

After the talks were scrapped, Afghans braced for an increase in violence.

The Taliban have opposed the elections and refused to meet representatives of Mr Ghani’s government for talks. They have also refused to agree to a ceasefire.

But it was two attacks in Kabul in recent weeks that caused Mr Trump to halt the negotiations with the Taliban, including one that killed two Nato soldiers, one of whom was an American. Another US soldier died in combat in Afghanistan on Monday.