The siege ended nearly 15 hours after the Somali group's gunmen shot their way into the Garissa University College campus in a pre-dawn attack, sparing Muslim students and taking many Christians hostage.
Interior Minister Joseph Nkaissery said four gunmen strapped with explosives were behind the attack, the same number that killed 67 people during the 2013 bloodbath at a shopping mall in Nairobi.
"The operation has ended successfully. Four terrorists have been killed," Nkaissery told Kenyan media.
Kenyan police chief Joseph Boinet said the attackers had "shot indiscriminately" when they entered the university compound.
Police and soldiers surrounded the campus and exchanged gunfire with the attackers throughout the day but were repeatedly repelled. At least 79 people were injured and many airlifted to Nairobi, Kenya's national disaster body said.
Al Shabaab, who carried out the deadly attack on the Westgate shopping mall in Nairobi in 2013, claimed responsibility for the raid on the campus in Garissa, a town 200 km (120 miles) from the Somali border.The group has links to al Qaeda and a record of raids on Kenyan soil in retaliation for Nairobi sending troops to fight it in its home state of Somalia.Al Qaeda bombed the United States embassies in Kenya and Tanzania on the same day in 1998, killing 224 people and wounding thousands of people.