Initial reports indicate attackers detonated an explosion before entering the hospital compound, he said.
"We don't have armed guards inside the hospital and that was why the attackers easily got inside and did their job". He said Afghan forces had battled the attackers floor by floor.
Defence Ministry spokesman Dawlat Waziri said the attack was suppressed by mid-afternoon with all three gunmen killed.
Wednesday's attack reflected the Afghan militants' capability to strike at the country's heavily guarded capital despite government efforts to improve security for ordinary Afghans.
"Our forces landed on the roof of the hospital from helicopters and were bravely fighting the enemies", Waziri said.
The area was blocked off by security forces.
A Taliban spokesman, Zabiullah Mojahid, denied responsibility for the attack in a tweet, saying: "today's attack on hospital in Kabul has nothing to do with the Mujahidin of Islamic Emirate", using the group's formal name.More news: Soy may improve survival rates in some breast cancer patients
More news: Google Denies Claims on Cheaper Pixel Models, Says Pixel 2 will…
More news: Immigration expert to speak after flood of recent raids and arrests
Men watch clashes at the biggest military hospital from Wazir Akbar Khan hilltop, between insurgent fighters and army soldiers at the gate of the hospital, in Kabul, Afghanistan, Wednesday, March 8, 2017.
The IS claimed responsibility in a statement that read: "Infiltrators from the Islamic State attack the military hospital in Kabul". The armed attackers proceeded to target patients and medical workers before Afghan security forces ended the assault.
The attack on a hospital that treats military casualties from around Afghanistan drew wide condemnation and President Ashraf Ghani said it "trampled on all human values".
The UN Security Council also condemned the attack in a statement released on Thursday and urged all states to cooperate with the Afghan government to bring those responsible to justice and to suppress the financing of "terrorism".
"This atrocity shows how Afghan people's desire and hope for a peaceful future is interrupted by unspeakable violence over and over again", said Ms Kardel. The Chinese side deeply mourns for the victims, and expresses sympathy with the injured and the bereaved families.
"Targeting a medical facility providing care for the courageous Afghans working to protect their fellow citizens has no possible justification in any religion or creed", said the spokesman to the Independent.
Afghan security forces have struggled to combat both groups since the USA and North Atlantic Treaty Organisation formally concluded their combat mission at the end of 2014, switching to an advisory and counter-terrorism role.