Afghan security forces run to the Justice Ministry building following an attack in Kabul on Wednesday.Afghan security forces run to the Justice Ministry building following an attack in Kabul on Wednesday. (Musadeq Sadeq/Associated Press)

Taliban fighters, some detonating suicide vests, attacked three government buildings in Kabul on Wednesday, killing at least 20 people, officials said.

At least five gunmen stormed a Justice Ministry building in the central part of the capital of Afghanistan on Wednesday morning, ministry official Mohammad Ali said. The men appeared to control the building for a short period.

All five insurgents were reportedly killed in a shootout with Afghan security forces.

Two hours after the gunmen stormed the building, Afghan security forces waved from windows in an apparent all-clear sign, according to an Associated Press reporter on the scene.

A ministry worker said he scrambled out of a second-floor window to escape an advancing gunman.

"I was in my office on the second floor of the Justice Ministry when I heard the sound of a strong explosion on the first floor," ministry employee Nazir Mohammad told the Associated Press.

"I came out of my office to see what was going on and I saw a man with an AK-47 shooting at every employee he saw in the hall. I saw three employees dead, including one of my colleagues.

Suicide bombers hit 2nd building

Two suicide bombers detonated a blast in another government building, responsible for Afghanistan's prisons, the BBC reported. A Taliban spokesman said the attacks were in retaliation for the treatment of its jailed insurgents.

At least 20 people were killed in the attacks and 57 wounded, said Mohammad Hanif Atmar, the interior minister.

Defence Ministry spokesman Gen. Mohammad Zahir Azimi said eight attackers were also killed in the attacks, including one assailant outside a third government building.

All of the insurgents involved in the two attacks wore suicide vests, he said, but only three of them detonated. The BBC quoted a senior source as saying several police were killed.

In a third incident near the Education Ministry, police shot dead another attacker, said police officer Zulmay Khan, which would bring the total number killed in all the attacks to 28.

No one else was reported to have been killed at that scene and it was unclear if the attacker had been targeting the Education Ministry, which is close to the Justice Ministry.

Canada's Kandahar provincial reconstruction team confirmed in a statement that the attacks did not occur in the vicinity of the Canadian Embassy in Kabul.

"All Canadian staff are safe and accounted for," the statement said. "The embassy monitors the security situation closely and has taken appropriate measures to protect personnel."

Intelligence agency had some warning of 'spectacular' attack

Amrullah Saleh, chief of Afghanistan's intelligence agency, said intelligence officials had some warning of a "spectacular" attack, but did not know enough to prevent it.

The insurgents involved in the attacks sent three text messages to the leader of their cell in Pakistan before launching Wednesday's assault, said Saleh, underlining the links between militants in the two countries.

He said 21 suspects had been detained in connection with the Kabul attacks.

The co-ordinated attacks — in the heart of the city and a stone's throw from the presidential palace — come ahead of a visit by Richard Holbrooke, U.S. President Barack Obama's special envoy to the region.

The Taliban regularly use suicide bombings in their assaults on Afghan and foreign troops, but the heavily barricaded capital had been largely spared of major attacks in recent weeks.

With files from the Associated Press