Al-Shabaab gunmen rampaged through a university in northeastern Kenya at dawn Thursday, killing 147 people in the group's deadliest attack in the East African country. Four militants were slain by security forces to end the siege just after dusk.

The masked attackers — strapped with explosives and armed with AK-47s — singled out non-Muslim students at Garissa University College and then gunned them down without mercy, survivors said. Others ran for their lives with bullets whistling through the air.

Amid the massacre, the men took dozens of hostages in a dormitory as they battled troops and police before the operation ended after about 13 hours, witnesses said.

Witness describes attack to CBC Radio's As It Happens

Augustine Alanga, who was inside a school residence when the shooting started, told CBC's Carol Off that once he realized what was happening he grabbed his phone and fled.

He said he ran outside barefoot and half-dressed, climbed the school wall and ran to the forest.

"I looked at them once, only once, but I saw them wearing masks and with sophisticated weapon," he said.

Alanga made it out of the area under attack safely, but said he has cuts on his legs from a barbed wire fence.

The 21-year-old student said he won't be going back to the school. Listen to Carol Off's full interview with Alanga on CBC Radio's As It Happens.

When gunfire from the Kenyan security forces struck the attackers, the militants exploded "like bombs," Interior Minister Joseph Nkaissery said, adding that the shrapnel wounded some of the officers.

Group vowed retaliation for Kenya's interference in Somalia

Al-Shabaab spokesman Ali Mohamud Rage said fighters from the Somalia-based extremist group were responsible. The al-Qaeda-linked group has been blamed for a series of attacks in Kenya, including the siege at the Westgate Mall in Nairobi in 2013 that killed 67 people, as well as other violence in the north.

The group has vowed to retaliate against Kenya for sending troops to Somalia in 2011 to fight the militants staging cross-border attacks.

Most of the 147 dead were students, but two security guards, one policeman and one soldier also were killed in the attack, Nkaissery said.

At least 79 people were wounded at the campus, which is in the capital of Garissa county, 145 kilometres from the Somali border, he said. Some of the more seriously wounded were flown to Nairobi for treatment.

A Kenya Defence Force soldier looked for cover near a perimeter wall after attackers targeted a campus in Garissa. (Noor Khamis/Reuters )

A dusk-to-dawn curfew was ordered in Garissa and three nearby counties.

One suspected extremist was arrested as he tried to flee, Nkaissery told a news conference in Nairobi.

Police identified a possible mastermind of the attack as Mohammed Mohamud, who is alleged to lead al-Shabaab's cross-border raids into Kenya, and they posted a $220,000 bounty for him. Also known by the names Dulyadin and Gamadhere, he was a teacher at an Islamic religious school, or madrassa, and claimed responsibility for a bus attack in Makka, Kenya, in November that killed 28 people.

'Footsteps and gunshots'

One of the survivors of Thursday's attack, Collins Wetangula, told The Associated Press he was preparing to take a shower when he heard gunshots coming from Tana dorm, which hosts both men and women, 150 metres away. The campus has six dorms and at least 887 students, he said.

When he heard the gunshots, he locked himself and three roommates in their room, said Wetangula, who is vice-chairman of the university's student union.

If you were a Christian, you were shot on the spot. - Collins Wetangula, student

"All I could hear were footsteps and gunshots. Nobody was screaming because they thought this would lead the gunmen to know where they are," he said.

"The gunmen were saying, 'Sisi ni al-Shabaab."' The phrase is Swahili for "We are al-Shabaab."

He heard the attackers arrive at his dormitory, open the doors and ask if the people who had hidden inside were Muslims or Christians.

"If you were a Christian, you were shot on the spot," he said. "With each blast of the gun, I thought I was going to die."

The gunmen then started shooting rapidly, as if exchanging fire, Wetangula said.

"The next thing, we saw people in military uniform through the window of the back of our rooms who identified themselves as the Kenyan military," he said. The soldiers took him and around 20 others to safety.​

'Fierce shootout'

As terrified students streamed out of buildings, arriving police officers took cover. Kenya's National Police Service said a "fierce shootout" ensued as police guarded the dorms.

Three dorms were evacuated as the gunmen holed up in a fourth, and Kenyan Defence Forces surrounded the campus.

"I am saddened to inform the nation that early today, terrorists attacked Garissa University College, killed and wounded several people, and have taken others hostage," President Uhuru Kenyatta said in a speech to the nation while the siege was underway.

After the militants took hostages, fears arose over the fate of some of the students, but the National Disaster Operations Center said all were eventually accounted for.

Al-Shabaab gunmen attacked Garissa University College in northeast Kenya early Thursday, targeting Christians and leaving as many as 150 dead. (Associated Press)

The U.S. condemned the attack, with White House spokesman Josh Earnest saying Washington was standing with the people of Kenya, "who will not be intimidated by such cowardly attacks." UN Secretary General Ban Ki-moon also condemned it, reiterating his solidarity with the Kenyans "to prevent and counter terrorism and violent extremism," his office said.

Wetangula, who was rescued by troops, said one soldier instructed a group of students to run and to dive for cover at their command as they ran to safety.

"We started running, and bullets were whizzing past our heads, and the soldiers told us to dive," Wetangula said. The soldier told students later that al-Shabaab snipers were perched on a three-storey dormitory called the Elgon, he said.

Police training to be accelarated

Kenyatta has been under pressure to deal with insecurity caused by a string of attacks by al-Shabaab.

In his speech to the country, he said he had directed the police chief to speed up the training of 10,000 police recruits because Kenya has "suffered unnecessarily due to shortage of security personnel."

Kenya's northern and eastern regions near the Somali border have seen many attacks blamed on al-Shabaab.

Last month, al-Shabab claimed responsibility for attacks in Mandera county on the Somali border in which 12 people died.

Police said 312 people have been killed in al-Shabaab attacks in Kenya from 2012 to 2014.

Last week, the group claimed responsibility for a siege at a Mogadishu hotel that left 24 people dead, including six attackers.