A group of as many as nine gunmen have attacked a restaurant in the diplomatic quarter of the Bangladeshi capital, Dhaka, killing at least two policeman.

The Islamic State of Iraq and the Levant (ISIL, also known as ISIS) group claimed responsibility for Friday's attack in Gulshan area.

At least 20 civilians, mostly foreigners, were held hostage inside O'Kitchen restaurant. Two of them, a chef and an electrician of the restaurant, were later rescued from adjacent building by special forces.

The remaining hostages were thought to include Italian citizens.

Italy's Foreign Minister Paolo Gentiloni said on Twitter he was closely following the situation in Dhaka, adding he was "anxious for Italians involved" and expressing solidarity with their families.

Benazir Ahmed, the head of the elite Rapid Action Battalion, an anti-crime unit, said on Friday night that his team was working to try and save the lives of the people stuck inside the restaurant.

"We would like to resolve the situation peacefully," he said. "And I urge everyone to remain calm and not to panic."

A large contingent of security personnel had cordoned off the area around the restaurant and members of the local police's were on site.

"Some of our people have been injured. Our first priority is to save the lives of the people trapped inside," the security chief said.

Sumon Reza, a supervisor at the Holey Artisan bakery that operates in the same building as the restaurant, escaped the attack. He told the Dhaka Tribune that he saw two slim attackers who appeared to be under 30 carrying small firearms and at least one had a sharp weapon with him.

Reza said the attackers were shouting Allahu Akhbar - God is the greatest in Arabic.

Bangladesh has recently seen an upsurge in violence in recent years [Stringer/AP]

Al Jazeera's Maher Sattar, reporting from Dhaka, said: "It's a place where you have a lot of foreigners … you have a lot of Bangladeshi elite … and is quite popular among the diplomatic corps. That makes one wonder if that’s the reason why it was chosen."

The US Embassy in Dhaka said on its Twitter feed that there were "reports of shooting and hostage situation".

Reports of shooting and hostage situation in Gulshan 2, Dhaka. Please shelter in place and monitor news.

Bangladesh has recently seen an upsurge in violence in recent years. Nearly two dozen atheist writers, publishers, religious minorities, social activists and foreign aid workers have been killed since 2013 by attackers.

Edward Rees, the peace and development advisor at the UN in Dhaka, told Al Jazeera the attack on the restaurant is "a new twist on an old story."

"Bangladesh has a history of these type of problems, but also has had a history of resolving them to some extent over the last 10 or 12 years," he said.

Talha Ahmed, a commentator on Bangladeshi affairs, told Al Jazeera that ISIL has claimed responsibility for at least three previous attacks, but that the Bangladeshi government has continued to deny the group has any presence in the country.

"There were at least three other previous incidents where ISIL claimed responsibility, [but] the Bangladesh government continued to deny that ISIL could have any connection or presence in Bangladesh. So if ISIL wanted to make a statement that [they] are in Bangladesh…then this is probably their perfect opportunity."