At least 28 people have been killed and over 20 others injured after gunmen attacked a government building in the Afghan capital Kabul, authorities have said.

The seven-hour standoff with police ended earlier this evening, according to officials.

Among those killed were a policeman and three of the attackers who were shot dead by Afghan security forces, Interior Ministry spokesman Najib Danish said.

The attack began in the afternoon when a suicide bomber blew himself up in a car outside the public works ministry.

Militants then stormed the building of the National Authority for Disabled People and Martyrs’ Families, taking civilians hostage as they fought a gun battle against Afghan soldiers.

Afghan security forces went from floor to floor of the building in an operation to rescue over 350 people inside, but had to exercise restraint in their operations against the attackers given the number of employees there, a senior security official said.

No militant group immediately claimed responsibility for the attack.

Ambulances raced to the scene during a lull in the shooting, a witness who lives nearby told Reuters. At least 20 people wounded in the clashes were taken to hospital.

An official working in another government building close by said employees had locked themselves in their offices after hearing the explosions and gunfire.

During the standoff, the building's second floor caught fire, local news channels reported.

Attacks on government offices are frequent and are generally carried out by the Islamist Taliban, who are fighting to expel foreign forces from strategic provinces, topple the Western-backed government and restore their version of hardline Islamic law.

The 17-year-old war with the Taliban has seen both fighting and diplomacy intensify in recent months.

On Thursday, an official said US President Donald Trump was planning to withdraw at least 5,000 of the 14,000 US troops in Afghanistan, a day after Mr Trump unexpectedly announced that US troops in Syria would be withdrawn.

At present, American troops make up the bulk of the Resolute Support mission to train and advise Afghan forces fighting the Taliban and the Islamic State militant group.

Others are part of a U.S.-led counter-terrorism mission.

The prospect of a US drawdown has triggered widespread uncertainty in war-torn Afghanistan.

With security deteriorating, Afghan President Ashraf Ghanion has replaced his defence and interior ministers with two uncompromising opponents of the Taliban.