GARISSA, Kenya — Elosy Karimi curled up in a crawl space, immobilized by fear.

Her classmates were flooding out of the dorms, in boxer shorts and thin nightgowns. Gunfire was ringing all around her. People were screaming. It was predawn and pitch black.

“If you want to survive, come out!” the militants yelled. “If you want to die, stay inside!”

In the terrifying confusion, Ms. Karimi, 23, decided to risk it inside, she said, and stayed hidden in the ceiling above her bunk bed for the next 28 and a half hours.

“I knew those guys were lying,” she said at the hospital, having just arrived to be checked after the ordeal.