KABUL -

Eight Taliban gunmen wearing suicide vests attacked three Afghan government buildings Wednesday in a co-ordinated assault that killed 20 people in Kabul before a visit from the new U.S. envoy to the region.

The attacks in a capital city dense with barricades and armed guards underscored the difficulty of fending off the Taliban even with abundant troops and weaponry as the U.S. beefs up its presence.

The assailants sent three text messages to the leader of their terror cell in Pakistan before launching the assault, said Amrullah Saleh, chief of Afghanistan's intelligence agency.

Five men armed with assault rifles and grenades attacked the Justice Ministry in late morning, shooting at workers and temporarily trapping the minister and scores of others inside, witnesses said. The gunmen appeared to hold the building for about two hours before Afghan security forces regained control about midday, according to an AP reporter on the scene.

At about the same time, two men in suicide vests blew themselves up at the ministry's correction department across town. A third assailant in a suicide vest was shot as he tried to force his way into the Education Ministry, about one kilometre from the Justice Ministry attack, said Defence Ministry spokesman Gen. Mohammad Zahir Azimi.

At least 20 people were killed in the attacks and 57 wounded, said Mohammad Hanif Atmar, the interior minister. All eight attackers died, Azimi said, bringing the total death toll to 28.

The Canadian Embassy, with a staff of 44, is not in the vicinity of the attacks, a Canadian official said.

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

Zabiullah Mujaheed, a spokesman for the Taliban, said the attacks were in response to the alleged mistreatment of Taliban prisoners in Afghan government jails.

"We have warned the Afghan government to stop torturing our prisoners," Mujaheed said in a phone call from an undisclosed location. "Today we attacked Justice Ministry compounds."

Saleh, the intelligence chief, said officials had intelligence indicating a "spectacular" attack involving multiple suicide bombers was imminent, but said they did not have enough specifics to prevent it.

He compared the attacks to the assault on hotels, markets and a train station in Mumbai last November that killed 164 in India. Indian officials have blamed the Mumbai attack on the Pakistani-based militant group Lashkar-e-Taiba. Saleh did not offer any more specifics.

Twenty-one suspects were detained, he said.

The incident comes as Richard Holbrooke, U.S. President Barack Obama's newly appointed envoy to the region, is expected imminently in Afghanistan from neighbouring Pakistan. Obama has vowed to increase U.S. focus on the resurgent Taliban, including sending more troops and designating Holbrooke, who is helping the administration chart a new strategy to beat the insurgencies raging in both countries.

The Taliban regularly use suicide bombings in their assaults on Afghan and foreign troops, but attackers have rarely made it inside the barricaded and guarded compounds of government buildings in the capital.

"They used grenades and AK-47s," Justice Minister Sarwa Danesh said of the attackers, speaking by mobile phone while he was briefly trapped inside the ministry with government employees.

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

"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," said ministry employee Nazir Mohammad, shaking as he spoke.

The attack follows an assault last month in which a Taliban suicide bomber attacked vehicles on a road that runs by both the German Embassy and a U.S. military base. One U.S. service member and four Afghan civilians died.

Elsewhere, in Logar, one province south of Kabul, a roadside bomb exploded near a French military medical team's convoy, killing one French officer and two Afghans, said Den Mohammad Durwesh, the governor's spokesman. The French government said another soldier was seriously injured.

Also in Logar, a helicopter with the U.S.-backed coalition killed five civilians as it responded to ground fire, Durwesh said. U.S. spokesmen could not immediately be reached for comment.