As families and friends mourn the loss of those killed in an attack on a military hospital in Kabul, Afghan officials launched an investigation on those responsible for the assault.

Gunmen dressed in white lab coats stormed the Sardar Daud Khan hospital in the centre of the capital on Wednesday, firing shots, detonating explosives and then battling security forces for hours. The assault resulted in the deaths of more than 40 people.

The Afghan interior ministry and the defence ministry on Thursday announced a probe into a claim by the Islamic State of Iraq and the Levant (ISIL) armed group that it was behind the attack.

READ MORE: Stop targeting humanitarian workers

"We are assessing Daesh claims to yesterday's attack, but at this stage we can't make a prejudgment prior to conclusion of investigation," Sediq Sediqqi, the spokesperson of the Afghan ministry of interior said in a tweet, using an Arabic acronym for ISIL, also known as ISIS.

"Brutal terrorist groups like ISIS (ISIL), Taliban, Haqqani and many other regional terrorist networks with safe havens in Pakistan have been behind many horrific attacks in the past," he added.

The Afghan Taliban, which attacked the Sardar Daud Khan hospital in 2013 killing six people, denied responsibility for Wednesday's assault.

According to US military officials, ISIL has about 700 fighters in Afghanistan. The group has previously claimed responsibility for a number of attacks that resulted in a large number of casualties, including a twin suicide bombing at a protest march in Kabul last year that left at least 80 people dead.

'ISIL not strong enough'

As reports emerged of ISIL's claim of responsibility, some analysts said the group does not have the capacity to conduct an attack of this magnitude.

"[ISIL] is still trying to gain a foothold in the east of the country," Inayatullah Kakar, an Afghan security and political analyst, told Al Jazeera.

"ISIL does exist in Afghanistan, but for them to conduct an attack like this in an area that is heavily guarded and with this calibre that killed so many people, it doesn't seem possible, as they are still trying to gain territories in eastern Afghanistan, while fighting the Taliban."

READ MORE: ISIL expands in Afghan-Pakistan areas, widening attacks

Kakar said the attack was carried out at a time of worsening relations between Afghanistan and Pakistan, with the two countries accusing each other for assaults within their borders.

"Pakistan blames Kabul for sheltering Tehreek-e-Taliban [TTP or Pakistani Taliban] elements while the Afghan government accuses Pakistan for supporting the Afghan Taliban," Kakar said.

The relationship between the two neighbours soured further following border clashes in recent months, and Pakistan has since tightened entry restrictions.

Calling Afghanistan's current security situation "murky", Kakar said it was hard to determine which armed group was behind Wednesday's attack.

"This hospital was previously attacked by the Taliban, and some of observers in Kabul believe it could the Taliban this time as well, but now the Taliban is looking into [improving its] political image. So when the civilian casualties are high, they deny involvement as now they are trying to make peace with the Afghan government," Kakar added.

Roughly 70 percent of ISIL fighters in Afghanistan are made up of TTP members, an armed group waging a rebellion against the Pakistani state, according to General John Nicholson, a top US commander in Afghanistan.

Nicholson said that these fighters were forced out of Pakistan by the Zarb-e-Azb military operation, which started in 2014, in an effort to wipe out armed groups and their bases in the North Waziristan tribal area.

He added that many ISIL fighters in Nangarhar province came from Pakistan tribal agencies.

'My death was near'

Mohammed Noor, a doctor, was present at the time of the hospital attack, treating his patients on the third floor of the building.

He heard gun shots and went downstairs to inquire, coming face-to-face with one of the attackers.

"He was wearing a white lab coat and was carrying an automatic weapon. He looked me in the eye and I froze," Noor told Al Jazeera.

"I told him 'I don't know who you are, but I am a doctor, don't shoot me.'

"That is all I could think of saying and ran. He screamed saying: 'I am going to shoot you', but I managed to run back to the third floor and took three of my patients with me and hid in a storage room."

READ MORE: Afghan Forces should learn from NATO's mistakes

Afghan army forces battled the fighters for seven hours, while evacuating survivors from the building.

The troops eventually found Noor and his three patients hiding.

"'The member of the security forces assured me that the fighter will kill him first, not me, so I should not worry. At that point, I was broken and messaged my mother to forgive me if I've ever hurt her, because I felt my death was near," Noor said.

Another doctor, who wished to remain anonymous, was evacuated through a window by the security forces.

"I think the death toll is much higher than 30," he said. "The entire building was full of dead bodies and blood. I am still in shock and cannot forget the floor painted with blood."

While funerals were under way on Thursday, many Afghans took to Twitter to condemn the attack.

#AFG Docter Behroz Bahnam was killed in yesterday's terrorist attack against main military hospital. Huge loss for Afghanistan. pic.twitter.com/flBtgCV0yx

— BILAL SARWARY (@bsarwary) March 9, 2017

We strongly condemn the Kabul hospital attack. Humanitarian medical personnel must be able to work without fear or restriction. #notatarget — OCHA Afghanistan (@OCHAAfg) March 8, 2017

#Afghanistan: We condemn the malicious double attack in #Kabul in the strongest terms. Our thoughts are with victims, families and friends. — GermanForeignOffice (@GermanyDiplo) January 10, 2017

The UN Security Council denounced the attack in a statement released on Thursday and urged the international community to cooperate with the Afghan government to bring those responsible to justice and to suppress the financing of "terrorism".

In a statement on Wednesday, Human Rights Watch called the attack a war crime.

More than 240 attacks targeting medical facilities and personnel were recorded from 2015 to 2016 in Afghanistan, according to a recent report by the Watchlist on Children and Armed Conflict.

A total of 3,498 civilians were killed and 7,920 were wounded in 2016, a combined increase of three percent over the previous year, according to a UN report.