The international charity Doctors Without Borders said at least 16 people including nine local staffers were killed when its clinic came under "sustained bombing" in the northern Afghan city of Kunduz.
Afghan officials said helicopter gunships had returned fire from Taliban fighters sheltering in the facility.
The group said the facility, which was treating more than 100 patients, came under attack at 2.10am local time. The charity did not say whether insurgents were present, and it was not immediately clear whether the staffers were killed by the Taliban, government or US forces. The group said another 30 people were still missing after the incident.
The dead included seven patients from the intensive care unit, among them three children. A total of 37 people were injured, including 19 staff, and 18 patients and caretakers. Five of the injured staff were in a critical condition.
Afghan forces backed by US airstrikes have been battling the Taliban street-by-street in Kunduz since Thursday, to dislodge insurgents who seized the strategic city three days earlier in their biggest foray into a major urban area since the US-led invasion of 2001.
The Ministry of Defence said "terrorists" armed with light and heavy weapons had entered the hospital compound and used "the buildings and the people inside as a shield" while firing on security forces.
Dawlat Waziri, the ministry's deputy spokesman, told The Associated Press that helicopter gunships fired on the militants, causing damage to the buildings.
Interior Ministry spokesman Sediq Sediqqi said 10 to 15 "terrorists" had been hiding in the hospital at the time of the strike. "All of the terrorists were killed but we also lost doctors," he said. He said 80 staff members at the hospital, including 15 foreigners, had been taken to safety. He did not say what sort of strike had damaged the compound.
Brian Tribus, a spokesman for American forces in Afghanistan, said a US airstrike on Kunduz "may have resulted in collateral damage to a nearby medical facility" and that the incident was under investigation. He said it was the 12th US airstrike "in the Kunduz vicinity" since Tuesday.
Doctors Without Borders, also known by the French acronym MSF, said its trauma centre "was hit several times during sustained bombing and was very badly damaged." At the time, the hospital had 105 patients and more than 80 international and Afghan staff.
The UN human rights chief Zeid Ra'ad Al Hussein said that if an investigation found that the hospital was purposefully targeted, the incident could constitute a war crime.
Calling the incident "tragic, inexcusable and possibly even criminal," he said "if established as deliberate in a court of law, an airstrike on a hospital may amount to a war crime".
The US secretary of defence Ash Carter said an investigation is under way. "The area has been the scene of intense fighting the last few days. US forces in support of Afghan security forces were operating nearby, as were Taliban fighters," he said in a statement.
"While we are still trying to determine exactly what happened, I want to extend my thoughts and prayers to everyone affected. A full investigation into the tragic incident is under way in coordination with the Afghan government."
Doctors Without Borders said "all indications currently point to the bombing being carried out by international coalition forces".
In a statement, the organisation said the attack was a "grave violation of international humanitarian law" and demanded an independent investigation.
Afghan president Ashraf Ghani expressed his sorrow and said he and the commander of US and Nato forces in Afghanistan, US army general John Campbell, had "agreed to launch a joint and thorough investigation".