Mohamed Ahmed Abdi and Hussein Hassan Mustafa got 18 years in jail each.
Abdi was given an additional 15-year sentence for possessing propaganda that promotes terrorism.
“This court has to pass a sentence commensurate with the offence”, Chief Magistrate Francis Andayi told the two as they stood in the courtroom.
Abdi and Mustafa had been charged alongside Liban Abdullah Omar, but he was acquitted when the trial ended on October 7.
All three defendants are ethnic Somalis.
None of the actual gunmen, estimated to number about seven, was caught.
The attack laid bare the weaknesses of Kenya’s security forces. Soldiers and police fired at each other as they fought for days to dislodge the gunmen from the sprawling complex.
In recent years, Kenya has suffered a string of deadly attacks by Al Shabab, who want Nairobi to withdraw its troops from Somalia