Afghanistan's Defense Ministry says more than 30 people have been killed and dozens more wounded in an attack on a military hospital in Kabul that was claimed by the extremist group Islamic State (IS).

Medical officials said three gunmen wearing white lab coats began spraying bullets after a suicide bomber blew himself up on March 8 at the back entrance to the 400-bed facility, which is located near two civilian hospitals in Kabul's heavily guarded diplomatic quarter.

Officials initially said at least three people had been killed, but revised the figure upward after the Sardar Mohammad Daud Khan Hospital complex, across the street from the U.S. Embassy, was checked by security forces.

"More than 30 [were] killed and more than 50 wounded," said General Dawlat Waziri, a Defense Ministry spokesman. He said the attack set off a floor-by-floor battle with security forces that lasted for several hours.

The attackers, who the Health Ministry also said were dressed as health workers, were shot dead after special forces landed on the roof of the hospital in a military helicopter.

IS claimed responsibility for the attack in a statement on the site of its news agency Amaq. It said, "Islamic State commandos attack the military hospital in Kabul."

Although the attack came as the Taliban ramped up attacks before the start of its annual spring offensive, a Taliban spokesman told media outlets that the group did not know anything about the attack.

"Today's Kabul attack has no connection" with the Taliban, the spokesman said separately in a tweet.

Last week, dozens of people were killed and wounded in a series of Taliban attacks on a police building and an intelligence-service compound in Kabul.

The NATO-led Resolute Support mission said it was ready to assist Afghan security services.

Afghan President Ashraf Ghani condemned the attack during a speech on the occasion of the International Women's Day, calling it "an attack on all Afghan people and all Afghan women."

The U.S. Embassy in Kabul said it "strongly condemns the attack and offered its condolences to relatives of the victims.

"The attack demonstrates the blatant disregard for human life by those seeking to disrupt Afghanistan’s democratic progress," the embassy said on its website. "Targeting a medical facility providing care for the brave Afghans working to protect their fellow citizens has no possible justification in any religion or creed."