As explosions sounded nearby, Israeli forces on Tuesday ordered the evacuation of one of the last functioning hospitals in the Gaza Strip, according to two doctors and the Gazan health ministry, raising fears that troops would attempt to storm a facility crowded with patients and displaced people.

Adding to the terror of those inside the hospital, Israeli forces fired on people who tried to flee the medical compound on Tuesday, with some being killed or injured, the doctors said.

The scope of the evacuation order at the hospital, the Nasser Medical Complex in Khan Younis, was not immediately clear. Two doctors said the Israeli military had given assurances that patients and medical staff could stay at the hospital. But one of the doctors said the military announced on Tuesday, using a loudspeaker attached to a drone, that everyone had to leave immediately and that an attack was imminent.

“The situation is very dangerous,” said Khaled Al-Serr, a general surgeon at the hospital. He said that the Israeli military had indicated just a day earlier that the hospital, which has been surrounded by Israeli ground forces for weeks, was safe.

The surrounding city of Khan Younis has been a focus of Israel’s invasion of southern Gaza, with airstrikes killing hundreds of civilians and soldiers shooting people in the streets, according to the Gazan health ministry and Palestinian news media reports. Many Gazans who fled Israel’s military offensive in northern and central Gaza had sought shelter in Khan Younis, only to be forced to flee again as Israeli forces advanced deeper into the strip.

The Israeli military did not immediately respond to questions about the evacuation order and about the allegation that its forces had shot at those trying to flee.

The Israeli military says that Hamas uses hospitals as a cover for its operations, a claim that the group and medical officials have denied. Palestinians have sought shelter at hospitals even though Israeli forces have regularly launched strikes on and around them and in some cases raided hospital compounds.

Nahed Abu Taeema, the head of surgery at Nasser Hospital, said that explosions from airstrikes had grown closer to the hospital and more intense over the past few days. “But we won’t leave the hospital without our patients,” he said.

Amid the confusion over the evacuation order, many doctors and nurses, along with their family members who were sheltering at the hospital, had begun to pack their belongings and prepare to flee, Dr. Al-Serr said, even as leaving presented its own set of dangers.

There are about 8,000 people inside Nasser, he said, including badly wounded patients who have limb injuries and would be difficult to transport.

The situation inside the hospital has grown increasingly dire. Israeli strikes nearby caused fires that spread to the hospital’s medical equipment storage facility and supply warehouse, burning both nearly completely, said Dr. Ashraf Al-Qudra, the spokesman for the Gazan health ministry. Sewage has flooded into the emergency department, hindering the treatment of patients and threatening further spread of disease, he said.

The United Nations’ World Health Organization said that one of its teams was denied access to the hospital on Sunday. The head of the agency, Tedros Adhanom Ghebreyesus, wrote on social media that he was “deeply concerned about the safety of patients and health personnel due to the intensifying hostilities in the vicinity of the hospital,” and warned that hospitals and health workers “MUST be protected at all times.”

Aaron Boxerman and Rawan Sheikh Ahmad contributed reporting.

— Raja Abdulrahim reporting from Jerusalem