Gunfighting at a besieged restaurant in the Bangladeshi capital ended on Saturday and commandos rescued between eight and 10 hostages, a police official said.

Gunmen attacked the restaurant in the diplomatic area of Dhaka late on Friday and had been holding about 20 hostages, including foreigners, before police stormed the building to free those stuck inside.

The number of gunmen and hostages still in the restaurant was unclear, Mizanur Rahman Bhuiyan, a deputy director at the Rapid Action Battalion force, told Reuters.

Bhuiyan told Reuters that one foreigner, who they thought was Japanese, was among those who escaped after more than 100 commandos launched an operation to secure the upscale cafe in Dhaka.

ISIS, which has claimed the attacks, posted photos of what it said were dead foreigners killed in the assault on the cafe, where police believe eight to nine gunmen are holed up and armed with assault rifles and grenades.

Gowher Rizvi, an adviser to Bangladesh Prime Minister Sheikh Hasina, told Reuters that security forces had tried to negotiate a way out of the crisis.

Police said the gunmen attacked the upscale Holey Artisan restaurant in the Gulshan district of Dhaka, popular with expatriates, in an assault that began around 9 p.m local time on Friday.

Italian, Indian hostages

The assailants exchanged sporadic gunfire with police outside for several hours after the attack.

ISIS said 24 people had died. Bangladesh police denied that, saying two police officers had been killed and at least 20 people wounded.

AFP_CO1VY

Bangladeshi security personnel stand guard after gunmen stormed the restaurant. (STR/AFP/Getty Images)

Italian and Indian nationals are among the hostages, said a duty officer at Rapid Action Battalion's (RAB) control room. Italy's ambassador to Bangladesh, Mario Palma, told Italian state TV seven Italians were among the hostages.

A Japanese government spokesman, quoting Dhaka police, had said 12 people had been rescued but it was not known if any Japanese citizens were among them.

Sporadic gunfire

Rizvi, the Bangladesh prime minister's adviser, said the hostage crisis began when security guards in the diplomatic enclave noticed several gunmen outside a medical centre. 

When the guards approached, the gunmen ran into the restaurant, which was packed with people waiting for tables, he added. 

91337943

At least 13 people were rescued Saturday morning. (Mahmud Hossain Opu/Getty Images)

An employee who escaped told local television about 20 customers were in the restaurant at the time, most of them foreigners. 

The restaurant has a seating capacity of around 25 people. Some 15 to 20 staff were working at the restaurant at the time, the employee said. 

A police officer at the scene said that when security forces tried to enter the premises at the beginning of the siege they met a hail of bullets and grenades. 

Television footage showed a number of police being led away from the site with blood on their faces and clothes. Heavily armed officers were seen milling on the street outside. 

Bangladesh Attack

A resident near the scene of the attack said he could hear sporadic gunfire nearly three hours after the attack began. (Associated Press)

A resident near the scene told Reuters he heard sporadic gunfire for nearly three hours after the attack began. 

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

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

Prime Minister Matteo Renzi abruptly left a ceremony at the Colosseum in Rome on Friday evening to follow developments, a source at his office said. 

The U.S. State Department said all Americans working at the U.S. mission there had been accounted for. A spokesman said in Washington the situation was "very fluid, very live". President Barack Obama has been briefed about the attack, the White House said.

Spike in militant attacks

Over the past 18 months, militant violence has spiked in Bangladesh despite its tradition of secularism and religious tolerance.

Attacks have tended to be on individuals, often using machetes, and the raid on the restaurant was a rare instance of a more coordinated operation.

Earlier on Friday, a Hindu priest was hacked to death at a temple in Jhinaidah district, 300 kilometres southwest of Dhaka.

Both ISIS and al-Qaeda have claimed responsibility for many of the killings, although local authorities say no operational links exist between Bangladeshi militants and international jihadi networks. Bangladesh security officials say two local militant groups, Ansar-al-Islam and Jamaat-ul-Mujahideen, are behind the violence.

Ansar pledges allegiance to al-Qaeda, while Jamaat-ul-Mujahideen claims it represents ISIS.

"The bottom line is Bangladesh has plenty of local, often unaffiliated, militants and radicals happy to stage attacks in ISIS's name," said Michael Kugelman, South Asia associate at The Wilson Centre in Washington D.C..

ISIS had claimed more attacks in Bangladesh than in Pakistan or Afghanistan, he said.