A special anti-terrorism tribunal delivered the verdict in a crowded courtroom in the capital Dhaka. [AFP]

Seven Islamist extremists have been sentenced to death by a Bangladesh court over a savage 2016 attack that killed 22 people including 18 foreigners at a Dhaka cafe popular with Westerners.

A special anti-terrorism tribunal delivered the verdict in a crowded courtroom in the capital Dhaka, with judge Mojibur Rahman saying the attackers wanted "to draw the attention of Islamic State" group.

They wanted to "undermine public safety, create anarchy and "establish a Jihad(ist)" state, he said, adding that the seven "will be executed by hanging until they are pronounced dead".

Some of the men shouted "Allahu Akbar (God is greatest)" and "long live faith of Islam", before they were led to a police van.

An eighth man who had been charged was acquitted.

The brazen assault in July 2016 saw young men armed with assault rifles and machetes lay siege to the Holey Artisan Bakery cafe in Dhaka's well-heeled Gulshan neighbourhood.

Police investigators said the attack was aimed at destabilising the Muslim majority nation of 168 million people and to turn it into an Islamist state.

Nine Italians and seven Japanese were among the foreigners to be hacked or shot dead. Two policemen were also killed.

Military commandos stormed the cafe after a 10-hour standoff and freed more than two dozen hostages.

The attack fuelled tensions over Islamist extremism in the country.

The secular government launched a massive crackdown that saw more than 100 Islamist extremists killed and nearly 1,000 others arrested.

All five militants were killed when the military stormed the cafe.

Eight others -- including mastermind Tamim Ahmed Chowdhury, a Canadian of Bangladesh descent -- were killed during raids in Dhaka and its suburbs months after the attack.

The dead also included commanders of a new faction of the homegrown extremist group Jamayetul Mujahideen Bangladesh, which police blamed for most of the extremist attacks in the South Asian nation since late 1990s.

The hostage crisis marked an escalation from a spate of murders claimed by IS and Al Qaeda of rights activists, gay people, foreigners and religious minorities. It was seen as a major blow to the country's image as a moderate Muslim nation.