Hurling grenades and firing automatic rifles, the gunmen had stormed the university in the north-eastern town of Garissa at dawn as students were sleeping, shooting dead dozens before setting Muslims free and holding Christians and others hostage.
The government said at least 79 people were wounded in the assault near the lawless border with war-torn Somalia, several seriously, and there are fears the death toll may still rise.
In the final hour before darkness fell, Kenyan troops stormed a student dormitory where the gunmen were holed up as blasts and fierce gunfire rang out. Interior Minister Joseph Nkaiserry said the four died detonating their suicide vests as soldiers burst in shooting, with Western security sources reporting that several soldiers and hostages may have died in the final blasts.
Troops then continued to search the campus for any possible insurgents until the siege was declared over late on Thursday, with the national disaster operations centre saying it had "ended with all four terrorists killed."
The attack was claimed by Al-Qaeda-linked Shebab fighters, the same insurgents who carried out the Westgate shopping mall massacre in Nairobi in September 2013, when four gunmen killed at least 67 people in a four-day siege.
Shebab spokesman Sheikh Ali Mohamud Rage told AFP the gunmen had taken non-Muslims hostage, and that their mission had been "to kill those who are against the Shebab." The university siege marks the worst attack on Kenyan soil since the 1998 bombing of the US embassy in Nairobi by Al-Qaeda, when 213 people were killed by a huge truck bomb.