Inside the emergency room, witnesses said, more than 20 patients were waiting for treatment. A Chicago police sergeant told everyone to stay down, according to Steven White, a patient who was being treated in the emergency room at the time.

“He was shooting in the back and all the women started yelling and the kids started crying,” Mr. White said. “That’s when the sarge came in, and said, ‘Stay down.’”

At that point, workers tried to usher ill patients outside to safety. Others hid, huddled in hospital rooms. Officers and emergency vehicles streamed into the area near Michigan Avenue and 26th Street, and people were warned to stay away. Inside the hospital, teams of police officers could be seen darting down hallways, searching room by room.

Joan Fortune, a pharmacist who works at the hospital, said she had been talking to a customer about cough medicine when he asked whether she had heard about the shots being fired. Immediately, she said, a technician closed the rolling shutter to the pharmacy, locked the door and ran to a back area.

“We just sat there,” she said. “We heard arguing. We heard more shots.”

When the gunman entered the hospital, she said, he was about 10 or 15 feet away from her at one point, though separated by two sets of doors. After they huddled in silence for about 30 minutes, she said, police officers banged on the door and said it was safe to come out, guiding them outside.