Amaq also said 24 people had been killed and 40 injured, some of them foreigners, in the attack.

Bangladeshi police, however, reported that only two police had been shot dead and at least 15 people were injured and said they were trying to free the hostages peacefully.

In the latest flare-up of Islamist militant violence to hit the South Asian nation, police said eight to nine gunmen attacked the Holey Artisan restaurant in the upscale Gulshan area of Dhaka.

The assailants, believed to be carrying assault rifles and grenades, exchanged sporadic fire with police outside, hours after the attack began around 9 p.m. local time.

Bangladesh has seen an increase in militant violence in the last year-and-a-half, with a series of deadly attacks targeting atheists, gays, liberals, foreigners and members of religious minorities in the mostly Muslim country of 160 million people.

The violence has tended to be assaults on individuals, often using machetes, and the raid on the restaurant was a rare instance of a more coordinated operation.

Both Islamic State and al Qaeda have claimed responsibility for many of the killings, although local authorities say there are no operational links between Bangladeshi militants and international jihadi networks.