Media playback is unsupported on your device Media caption Sanjoy Majumder reports as gunmen take hostages at a popular cafe in the Bangladesh capital, Dhaka

Gunmen have stormed a popular cafe in the diplomatic area of the Bangladeshi capital, Dhaka, taking a number of hostages, officials say.

Several foreigners are among those being held by eight or nine armed men in the Holey Artisan Bakery cafe in the city's Gulshan district, they add.

Two police officers have been killed in a gun battle, a spokesman said, and about 30 others injured.

So-called Islamic State (IS) has said it carried out the attack.

A statement on the group's self-styled news agency Amaq said militants had attacked a restaurant "frequented by foreigners". It said that more than 20 people "of different nationalities" had been killed but this has not been confirmed.

Security forces say they are trying to negotiate the hostages' release.

Initial reports said that as many as 20 foreigners were among those taken captive.

Seven Italian nationals are believed to be in the cafe, the Italian ambassador in Dhaka, Mario Palma, was later quoted as saying by Italian media.

A Japanese government spokesman said Tokyo was investigating reports that some of its citizens were among the hostages.

Image copyright AP Image caption Passers-by helped to carry the injured away from the Holey Artisan Bakery

"We want to resolve this peacefully. We are trying to talk to the attackers," said Benazir Ahmed, chief of the Rapid Action Battalion, Bangladesh's elite police force.

"Our first priority is to save the lives of the people trapped inside."

Police said the gunmen burst into the Holey Artisan Bakery cafe at about 21:20 (13:20 GMT) and opened fire.

Analysis: Anbarasan Ethirajan, former BBC Bangladesh correspondent

This is probably the first time ever foreigners have been taken hostages in Bangladesh.

Though there have been a number of killings focusing on academics, activists and member of religious minorities, attacks on foreigners are rare.

The timing is important. Bangladesh has been gearing up for the Muslim religious festival of Eid, and most people have started going to their homes in villages and towns across the country for a week-long holiday period.

The government has always denied the presence of Islamic State militant group in Bangladesh.

So far the militants have targeted individuals and sometimes security forces. But storming a cafe in a heavily guarded diplomatic district is unprecedented and a dramatic escalation in violence.

The government has been caught unaware, and the attack exposes a big hole in Bangladesh's intelligence gathering and security system.

The cafe is described as being popular with expatriates, diplomats and middle-class families.

Image copyright Reuters Image caption A Dhaka hospital said about 30 police officers had been injured

Image copyright Getty Images Image caption Police and officers of Bangladesh's Rapid Action Battalion are at the scene

Media reports quoted witnesses as saying that "Allahu Akbar", meaning "God is greatest", was heard as the attack took place.

An eyewitness said she heard a loud noise, followed by continuous gunfire.

"The glass of my drawing room shattered," Rashila Rahim said.

"My auntie, her daughter and two friends went there for Iftar (breaking of the Ramadan fasting) and they have not come back. We cannot even check where they are."

Another local resident, Tarique Mir, said he could hear sporadic gunfire nearly three hours after the attack began.

"It is chaos out there. The streets are blocked. There are dozens of police commandos," he said.

BBC South Asia editor Jill McGivering says that although high-profile gun attacks are rare in Bangladesh, the latest incident follows a series of murders widely blamed on Islamist extremists.