Masked gunmen stormed the university in the north-east town of Garissa as students slept, hurling grenades and shooting others dead before freeing Muslims and taking Christians and others hostage.
Two police officers, one soldier and two watchmen were also killed in the assault, which lasted about 13 hours from when the first grenades were used before dawn to blast open the gates of the university, near the border with war-torn Somalia.
In the final hour before darkness, Kenyan troops stormed the dormitory where the gunmen were holed up as explosions and heavy gunfire rang out.
“We are mopping up the area,” said interior minister Joseph Nkaiserry. “This is the saddest attack that has happened in the history of Kenya.”
He confirmed that four gunmen had been killed after Kenyan troops launched an assault on the building.
Thursday’s attack is the worst in the country since the bombing of the US embassy in Nairobi by Al Qaeda, which killed 213 people.
Mr Nkaiserry said that troops were still scouring the campus because the number of gunmen was not known, but that the main operation was over.
The Al Qaeda-linked Al Shabab, the same group that carried out the Westgate shopping mall massacre in Nairobi in September 2013, claimed responsibility for the attack.
In that attack, four gunmen slaughtered at least 67 people in a four-day bloodbath.
Shabab spokesman Sheikh Ali Mohamud Rage said the gunmen had taken non-Muslims hostage, and that their mission had been “to kill those who are against the Shabab”.
It was not clear if any of the students the Shabab said they had held were alive at the time of the final assault by troops. However, officials said over 500 students had been accounted for.
“Kenya is at war with Somalia,” Rage said, referring to the thousands of Kenyan troops in Somalia as part of an African Union military mission.
Soldiers with tanks were deployed around the campus.
A $215,000 (Dh790,000) bounty was offered for the capture of alleged Shabab commander Mohamed Mohamud, a former Kenyan teacher believed to now be in Somalia and said to be the mastermind of the Garissa attacks.
British high commissioner Christian Turner condemned the “cowardly” attack, while US ambassador Robert Godec called the killings “heinous”.
UN envoy to Somalia Nicholas Kay said the attack showed once again the “shocking brutality of Al Shabab”.
The garrison town is around 150 kilometres west of Somalia and has in the past been targeted by militants from the Shabab.
Police chief Joseph Boinet said “the gunmen shot indiscriminately” after storming the compound.
The sprawling campus on the outskirts of town has both teaching areas as well as residential blocks. The university has several hundred students from different parts of Kenya.
A dawn until dusk curfew has been imposed on several northern and eastern Kenyan districts.
Kenya has been hit by a wave of grenade and gun attacks, often blamed on sympathisers of the Shabab and sometimes aimed at police targets, since the army crossed into southern Somalia in 2011 to attack bases of Muslim extremists.
A series of foreign travel warnings in response to the threat have crippled Kenya’s economically important tourism industry.
On Wednesday, just hours before the Garissa attack began, president Uhuru Kenyatta said Kenya “is as safe as any country in the world”.
On Thursday, he offered condolences to those killed, but said security forces had made the “appropriate deployment to the affected area”.
However, he also ordered the “urgent” enrolment of a planned 10,000 police recruit boost, warning Kenya had “suffered unnecessarily due to shortage of security personnel”.
Kenya’s government has been under fire since the Westgate attack. In June and July last year Shabab gunmen killed close to 100 people in a series of attacks on the town of Mpeketoni and nearby villages.
In November, Shabab claimed responsibility for holding up a bus outside Mandera town, separating passengers according to religion and murdering 28 non-Muslims. Ten days later 36 non-Muslim quarry workers were also massacred in the area.
* Agence France-Presse