The attack got under way when a suicide bomber detonated his explosives near the entrance of the sprawling site.
Gunmen then broke into the hospital grounds, firing their weapons there, the Taliban said.
“Nineteen dead bodies and about 50 wounded people have been taken to hospitals in Kabul,” a health ministry official who asked not to be named told AFP.
The Taliban spent 20 years waging an insurgency against the ousted US-backed government.
Now they face the struggle of bringing stability to Afghanistan, which has been hit in recent weeks by a series of bloody assaults claimed by the Islamic State group’s local chapter.
Tuesday’s attack has not yet been claimed by any group.
“All the attackers are dead. The attack was initiated by a suicide bomber on a motorcycle who blew himself up at the entrance of the hospital,” a Taliban official from the media team said.
“Some attackers entered the hospital compound.”
Two explosions targeted the hospital area, he had earlier said in a statement.
AFP staff in the city heard a second explosion some 30 minutes after the first was reported.
“I heard a big explosion coming from the first checkpoint. We were told to go to safe rooms. I also hear guns firing,” a doctor at the Sardar Mohammad Daud Khan hospital in Kabul told AFP while the attack was being carried out.
“I can still hear gun firing inside the hospital building. I think the attackers are going from room to room… like the first time it was attacked,” the doctor added.
Ambulances speeding through Kabul
The hospital, which treats wounded soldiers from both the Taliban and former Afghan security forces, was previously attacked in 2017, when gunmen disguised as medical personnel killed at least 30 people in an hours-long siege.
Although both IS and the Taliban are hardline Sunni Islamist militants, they differ on details of religion and strategy.
IS have claimed four mass casualty attacks since the Taliban takeover on August 15, including suicide bomb blasts targeting Shiite Muslim mosques. The group regards Shiite Muslims as heretics.
In the 2017 attack on the military hospital, militants went room to room killing people, switching to knives when they ran out of ammunition.
That attack was claimed by the Islamic State group, and the Taliban denied responsibility.
However, survivors told AFP that the attackers chanted “Long live Taliban” in Pashto and attacked all but two wards on the hospital’s first floor where Taliban patients were admitted.
An Italian NGO which runs a separate hospital in the capital tweeted on Tuesday that it has received nine patients with injuries from the blast site.
Pictures shared on social media showed black smoke billowing into the air after the explosions, the first of which went off at around 1:00 pm (0830 GMT).
AFP journalists saw Taliban fighters racing to the scene in at two armoured personnel carriers (APCs) and pick-up trucks.
Roads close to the heavily fortified “Green Zone” where the buildings of several former Western embassies were located were closed off to traffic and Taliban guards scaled up searches.