Christians targeted
The militants singled out Christians and shot them, witnesses said. They rampaged through the campus at dawn on Thursday, shooting and shouting "we are al-Shabab".
A spokesman later confirmed that the group — linked to al-Qaeda — was responsible. It says it is at war with Kenya, which sent troops to Somalia in 2011 to fight the militants.
Al-Shabab was also blamed for the Westgate Mall massacre in Nairobi in 2013 in which 67 people died.
Kenyan authorities are to hold an emergency meeting to assess security in the region. There has been criticism that Garissa should have been better protected.
The government has offered a reward of $53,000 (£36,000) for the man it says planned the killing — Mohamed Kuno, a former Kenyan schoolteacher, now thought to be in Somalia.
The heavily armed gunmen killed two security guards first, then fired indiscriminately at students, many of whom were still asleep in their dormitories.
Eric Wekesa, a student at Garissa, told Reuters he locked himself in his room before eventually fleeing.
"What I managed to hear from them is 'We came to kill or finally be killed.' That's what they said."
"It was horrible, there was shooting everywhere," another student, Augustine Alanga told the BBC's Newsday programme.
He said it was "pathetic" that the university was only guarded by two police officers.
Attack as it happened
How attack unfolded:
1. Militants enter the university grounds, two guards are shot dead
2. Shooting begins within the campus
3. Students attacked in their classrooms while preparing for exams
4. Gunmen believed isolated in the female dormitories
5. Some students make an escape through the fence