The attack on a cafe in 2016 killed 20 civilians, both foreign and Bangladeshi.
A special tribunal dealing with anti-terrorism cases handed down the punishment for carrying out a terrorist attack using firearms, murder and financing terrorism, prosecutor Abdullah Abu said.
One person was acquitted, he added.
Nine Italians, seven Japanese, one Indian, one U.S. and two Bangladeshi nationals were killed when radical Islamists attacked Holey Artisan Bakery, frequented by foreigners alongside local residents in Dhaka’s Gulshan diplomatic enclave, on July 1, 2016.
Two police officers were also killed before the military commandos stormed the restaurant, putting an end to an 11-hour siege.
The army killed five militants and one associate in its operation to free hostages.