A senior Taliban spokesman said the explosion tried to target "civilians, doctors, and patients" inside the 400-bed hospital.
Several people have been killed and dozens wounded after an explosion near a military hospital in Kabul.
The blast went off at the entrance to the Sardar Mohammad Dawood Khan military hospital in the Afghan capital.
The Taliban government defense ministry said that six attackers were behind the explosion on Tuesday morning.
The suspects tried to enter the facility before they were forced back by guards, and the Taliban regained control of the hospital, the ministry added.
"There are casualties among both our personnel and civilians but the toll is not immediately clear," a ministry spokesman said.
Taliban spokesman Zabihullah Mujahid blamed the attack on the so-called Islamic State and said seven people were killed outside the hospital entrance.
"Militants wanted to target civilians, doctors, and patients" inside the 400-bed hospital, Mujahid said on Twitter, adding that five attackers were also killed.
But there was no official confirmation of a second explosion that had been heard in the 10th district of Kabul. Residents said they also heard the sound of gunfire in the area.
Health officials have reported that at least three people had died and 16 were wounded in the blast.
Sayed Abdullah Ahmadi, the director of the nearby Wazir Akbar Khan hospital, said his facility had received three bodies and seven people who were injured.
Another nine injured were taken to the Afghanistan Emergency Hospital, according to The Associated Press.
There was no immediate claim of responsibility for the attack.
In recent weeks, the so-called Islamic State militant group has carried out a series of bombing and shooting attacks in Afghanistan since the Taliban takeover.