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.

New details emerged on Friday about how a handful of fighters from the Shabab militant group, with just a few light weapons, managed to kill nearly 150 students in Kenya’s worst terrorist attack since the 1998 bombing of the United States Embassy in Nairobi.

Image

Students evacuated from Garissa University College waited in a holding area on Friday before being taken back to their home regions.CreditCarl De Souza/Agence France-Presse — Getty Images

Survivors said many students had fallen for the militants’ trick, voluntarily leaving their dorm rooms and obeying commands to lie down in neat rows, only to be shot in the back of the head.

One of the militants appeared to be a trained sniper, some witnesses said, picking off several Kenyan soldiers and critically hampering the rescue effort, giving the gunmen hours more to keep killing.

The militants seemed especially cruel and gleeful, ordering some students to call their parents on their cellphones and tell them that the attack was payback for Kenya’s military intervention in Somalia.

Students who hid during the attack said they had heard their classmates whimpering as the militants taunted them. Then a single gunshot. Then silence.

“They were shooting people as they came out; they were making others lie down,” said a doctor who was not authorized to speak publicly. “They had so many people lying in one place, it was easy killing.”

Garissa, the hard, thorny frontier town that was the scene of the siege, is now a town on edge.

Huge military trucks with four-foot-tall tires thunder down the highway. Ambulances deliver bodies to the airport. Garissa University College, where the students were killed, has been sealed off, and young, nervous soldiers, dripping with sweat, try to hold back crowds of onlookers by swatting them with acacia branches.

Many students here said that universities in Nairobi had been warned about possible terrorist attacks; they were stunned that their campus, in an area where the Shabab has struck many times before, had only two guards.

The Shabab has killed hundreds of Kenyans — on country buses, in churches, in a quarry last year where they marched off miners before dawn and also made them lie face down in rows.

The worst Shabab attack before this was on Nairobi’s Westgate mall in 2013, when a few young Shabab gunmen killed dozens of shoppers, including small children.

“That’s what I was thinking when I heard the first burst of gunfire,” said Ibrahim Maalim, a guard at the school. “Westgate.”

Image

Students mourned the loss of friends, a day after Shabab militants killed nearly 150 of their classmates.CreditCarl De Souza/Agence France-Presse — Getty Images

The attack on Thursday exposed just how powerless this industrialized, westernized country is in the face of a ruthless terrorist organization. Many fear that Kenya cannot stop the Shabab, who are clearly trying to fan a religious war.

On Friday morning, a dozen local young men, all Muslim, marched down Garissa’s main road to show solidarity with the victims, the vast majority of whom were Christian and hailed from other parts of Kenya.

We will not succumb to this, the demonstrators said. We stand with you. We may be ethnic Somalis, but we are Kenyan, too.

Ahmed Youssouf, 28, said he was inside the university mosque with other Muslims on Thursday when the shooting began.

Immediately, Christian students began pouring inside seeking refuge, and their Muslim classmates hid them, he said. Many of the students later crawled out single file, dashing for the university’s gate, he said.

“I could see the mess of what was happening — children jumping out of rooms, running helter-skelter, others falling down with bullets,” he said.

Kenya’s military operation in Somalia began in 2011. It was intended to push the Shabab back from the border and protect Kenya’s security and economic interests. It does not seem to have achieved the intended effect.

Kenya’s tourism industry has been wounded by the perception the country is not safe. And for the first time in decades, a militant group in Kenya is stirring up not just religious tensions but territorial ones as well.

In the 1960s, Somalia’s government sent guerrilla fighters across its border with Kenya. It was called the Shifta War. This part of Kenya is predominantly ethnic Somali; Somalia said it was simply trying to reclaim what it considered long lost territory.

Now the Shabab are resurrecting that old argument. The Shabab tried to justify the attack on Thursday by saying this part of Kenya was “a Muslim land under colony.” A Shabab spokesman called the university part of Kenya’s “plan to spread their Christianity and infidelity.”

Image

Relatives of victims gathered pm Friday at a center set up for survivors of the attack and families.CreditBen Curtis/Associated Press

Not a single person among dozens interviewed here on Friday uttered a word of support for the Shabab, considered one of Al Qaeda’s most murderous branches.

But there was growing resentment toward the Kenyan government.

Aden Osman, a thin man with protruding collar bones and a hungry, vacant face, stood outside Garissa’s main hospital. The collar of his shirt was spattered with blood. A yellowing bandage was taped atop his head. At first glance, he could have easily been mistaken for a gunshot survivor.

But Mr. Osman said it was actually the government that had done this. He said, and witnesses seconded his account, that Kenyan soldiers thumped him with a club simply for showing up at the gates of the university to check on a friend whom he thought might have been killed.

“I will never like the Shabab,” Mr. Osman said. “But no government should be beating its own people.”

All that separates Kenya from Somalia is a thin dusty line. The 424-mile border is scarcely patrolled — the Kenyans do not have the resources for it.

Image

A Red Cross worker treated a Garissa student for shock on Friday as more details emerged about the deadly campus siege.CreditCarl De Souza/Agence France-Presse — Getty Images

Elders here say that the few guards who do run patrols are notoriously corrupt, letting smuggled sugar, illegal refugees, truckloads of guns and just about anything else pass through, for the right price.

The Kenyan government is now asking Western allies to help it build a massive border wall. But Somalia specialists say that may not be a cure-all.

This attack “was low-tech, low budget, low risk, and the target was low-hanging fruit,” said Kenneth Menkhaus, a professor at Davidson College in North Carolina.

“It says a lot more about how hard it is for an open society like Kenya, with tens of thousands of soft targets, to prevent a terrorist group from attacking them,” he added.

At the Chiromo Funeral Parlor in Nairobi, a long line of Land Rovers pulled up on Friday afternoon. They were delivering bodies that were wrapped in white sheets, blood soaking through. Soldiers in surgical masks hauled them into a morgue, and relatives began to weep.

“Some people may not be strong in these situations,” a Red Cross worker shouted over a bullhorn. “Hold the one next to you.”

Rukmini Callimachi contributed reporting from New York, and Isma’il Kushkush from Nairobi.

A version of this article appears in print on , on Page A1 of the New York edition with the headline: Promised Mercy, Kenyan Students Got Bullets. Order Reprints | Today’s Paper | Subscribe