An Israeli airstrike hit a tent camp inside the Al-Aqsa Martyrs Hospital compound in Deir el-Balah in central Gaza on Sunday.
Israel's military said it targeted a command center operated by the Islamic Jihad group, an ally of Hamas.
"The command center and terrorists were struck precisely, intended on minimizing harm to uninvolved civilians in the area of the hospital," the military said.
"The Al-Aqsa hospital building was not damaged and its functioning was not affected," it added.
Thousands of people have been sheltering in tents in the hospital's courtyard to escape the fighting in Gaza.
Reporters have also used the hospital courtyard as a safe place to work.
A reporter for the AP news agency based in tents nearby filmed the aftermath of the strike and said people including women and children scattered and cried out.
Two people were killed and 15 others wounded in the airstrike.
Fighting also reported at other Gaza hospitals
On Saturday, the Israeli military said it had "continued to eliminate" militants around the largest hospital, Al-Shifa in Gaza City, with around 200 reported killed after 13 days of fighting.
The Red Crescent reported Israeli operations were also ongoing at Al-Amal Hospital, and Hamas reported fighting at Nasser Hospital in the southern city of Khan Younis.
Israel said hospitals in Gaza are used by Hamas and other militant groups as bases, Hamas and medical staff deny this.
The UN World Health Organization warned that Gaza now has just 10 "minimally functioning" hospitals, down from 36 before the war.
The Health Ministry in Hamas-run Gaza said Sunday at least 32,782 Palestinians, mostly women and children, have been killed in the Israel-Hamas war, including 77 whose bodies were brought to hospitals over the last 24 hours.
The ministry does not differentiate between civilians and combatants.
Israel launched a ground operation in Gaza in the wake of the terror attack by Hamas and other militants in southern Israel on October 7, in which 1,200 people were killed and some 250 hostages taken.
Fresh round of talks in Cairo
On Sunday, indirect cease-fire talks resumed in Cairo despite the ongoing fighting.
Egypt, one of the mediators in the talks, hosted an Israeli delegation for the latest round of negotiations.
According to the Reuters news agency, Hamas negotiators were not present at the talks in Cairo as they were waiting to hear what Israel proposed.
The warring sides were discussing a six-week suspension of Israel's offensive in return for the proposed release of 40 of 130 hostages still held by Hamas militants in Gaza.