Taliban militants armed with assault rifles and wearing suicide vests stormed three government buildings in Kabul on Wednesday, killing 20 people and wounding 57 others, government officials reported.

Eight of the militants also died in the attacks, according to Gen. Mohammad Zahir Azimi, a spokesperson for the Afghan Defence Ministry, which brought the death toll to 28.

All eight attackers were wearing suicide vests, Azimi said, but only three detonated them.

Before launching their attack, the assailants sent three text messages to the leader of their terror cell in Pakistan, according to Afghanistan's intelligence chief Amrullah Saleh.

He did not offer further details of the militants' connection to Pakistan.

Around 10 a.m., five men carrying assault rifles and grenades stormed the Justice Ministry building, shooting at employees and forcing workers to flee from windows.

A ministry employee said he jumped out of a second-floor window to escape one of the gunmen.

"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 Nazir Mohammad.

Justice Minister Sarwar Danesh, who was briefly trapped in the building during the siege, told The Associated Press that the attackers "used grenades and AK-47s."

But by midday, all five militants were dead after a shootout with Afghan security forces, who gestured from the building's windows in what seemed to be an all-clear sign, The Associated Press reported.

As the attack at the Justice Ministry was underway, two more attackers blew themselves up at a correction department building in northern Kabul, according to Azimi.

A third attack near the Education Ministry left one attacker dead after he was shot by police, according to police officer Zulmay Khan.

It is unclear if the attacker was targeting the Education Ministry, which is also close to the Justice Ministry.

All 44 Canadians who work at the Canadian embassy in the capital are safe, according to a statement issued by an official with the Kandahar Provincial Reconstruction Team.

"The attacks today in Kabul did not occur in the area of the Canadian Embassy," the statement read.

"The Embassy monitors the security situation closely and has taken appropriate measures to protect personnel."

The attacks on the Afghan capital came ahead of a planned visit from U.S. President Barack Obama's special envoy to the region, Richard Holbrooke.

Obama plans to increase troop levels in the country in an effort to quash the activity of a resurgent Taliban network.

Wednesday's attacks indicate the Taliban's willingness to move out of its traditional strongholds in the south and east of the country.

Taliban spokesperson Zabiullah Mujaheed said the attacks were in protest against alleged mistreatment of Taliban prisoners in jails run by the Afghan government.

"We have warned the Afghan government to stop torturing our prisoners," Mujaheed told the Associated Press in a phone call from an unknown location.

The Afghan intelligence head indicated that officials did get intelligence that warned of a "spectacular" attack involving multiple suicide bombers. However, there weren't enough specific details available to prevent it, he said.

While Taliban militants have used suicide attacks against Afghan and foreign troops stationed in the country, the heavily fortified capital has not experienced any serious recent attacks.