The Episcopal Diocese of Jerusalem, which runs the Ahli hospital, said that the hospital administration had received at least three warnings from the Israeli military to evacuate its wards on Saturday, Sunday and Monday. The Archbishop of the Diocese, Rev. Hosam Naoum, said the warnings were issued by phone call and text message directly to their administration and were separate from the general warnings given to the more than one million residents of the northern Gaza Strip.

The Israeli military acknowledged that it did call the hospital in recent days, but it said it was part of a wider effort to encourage residents and community leaders in northern Gaza to flee southward — signaling that a ground invasion was coming. The call was not to warn of a specific strike on the hospital, said Lt. Col. Amnon Shefler, a military spokesman. The hospital “was not in any way a target,” he added.

After the first warning, the hospital staff notified the 5,000 or so people sheltering there. Most left and only about 200 remained, Mr. Naoum said. But the next day, many returned, having found no safer place as airstrikes pounded the city.

“Every time there’s bombing, every time there’s an airstrike, people flee to the hospital,” Mr. Naoum said. “This is a sanctuary for them.”

The warnings didn’t dissuade Sameh and his family from seeking refuge there. They had joined the thousands of people who fled their homes elsewhere in Gaza City to take shelter amid 11 days of Israeli airstrikes on the Gaza Strip.

Israel’s intense bombardment of Gaza began on Oct. 7 in response to a surprise attack by Hamas that killed roughly 1,400 people in Israel. Since then, Gazans have found that nowhere is safe, as homes, mosques, schools and hospitals have been struck. More than 3,500 Palestinians have been killed since the strikes began, according to the Gaza health ministry.

On Saturday, two Israeli projectiles hit the same hospital that was struck on Tuesday night, damaging the fourth floor, which housed a diagnostic center and the ultrasound and mammography units, the hospital administration said. However, the Israeli military denied that it had struck that area on Saturday.

Sameh said he and his family fled their home in Gaza City fearing that it could be in danger from Israeli rockets, and went to stay with an aunt. But then they grew concerned that her home was under threat as well, so they came to the hospital.

There, he found many other displaced Gazans staying in the courtyard, library and church.

“We felt it was safe, and we said it would be safe for the little kids,” he said from his hospital bed.

But Tuesday night, the courtyard where just hours earlier children were enjoying the hospital playground along with hospital staff became a scene of carnage.

“There are still lots of bodies they haven’t yet collected,” said Amir Ahmed, a paramedic with the Palestinian Red Crescent in Gaza City. “There are too many bodies.” He said all the victims would be buried in a mass grave at a funeral on Wednesday.

“There is a big possibility that they will just put a number” on the body bags without any names, Mr. Ahmed added, “because many are in pieces.”