Hosne Ara Karim, whose son and daughter-in-law were rescued from the restaurant that was attacked by heavily armed militants, wait for them in Dhaka, Bangladesh, Saturday, July 2, 2016. Bangladesh forces stormed the restaurant where militants held dozens of people hostage for 10 hours Saturday morning. (AP Photo)
Hosne Ara Karim, whose son and daughter-in-law were rescued from the restaurant that was attacked by heavily armed militants, wait for them in Dhaka, Bangladesh, Saturday, July 2, 2016. Bangladesh forces stormed the restaurant where militants held dozens of people hostage for 10 hours Saturday morning. (AP Photo)

The hostages were given a test: recite verses from the Quran, or be punished, according to a witness. Those who passed were allowed to eat. Those who failed were tortured and slain.

The dramatic, 10-hour hostage crisis that gripped Bangladesh’s diplomatic zone ended Saturday morning with at least 28 dead, including six of the attackers, as commandos raided the popular restaurant where heavily armed attackers were holding dozens of foreigners and Bangladeshis prisoner while hurling bombs and engaging in a gunbattle with security forces. The victims included 20 hostages, mostly foreigners, and two Bangladeshi police officers.

The attack marks an escalation in militant violence that has hit the traditionally moderate Muslim-majority nation with increasing frequency in recent months, with the extremists demanding the secular government revert to Islamic rule. Most previous attacks have involved machete-wielding men singling out individual activists, foreigners and religious minorities.

But Friday night’s attack was different, more coordinated, with the attackers brandishing assault rifles as they shouted “Allahu Akbar” (God is Great) and stormed the Holey Artisan Bakery in Dhaka’s Gulshan area while dozens were dining out during the Ramadan holy month.

The gunmen, initially firing blanks, ordered restaurant workers to switch off the lights, and they draped black cloths over closed-circuit cameras, according to a survivor, who spoke with local TV channel ATN News.

But about 35 were trapped inside, their fate depending on whether they could prove themselves to be Muslims, according to the father of a Bangladeshi businessman who was rescued Saturday morning along with his family.

“The gunmen asked everyone inside to recite from the Quran,” the Islamic holy book, according to Rezaul Karim, describing what his son, Hasnat, had witnessed inside. “Those who recited were spared. The gunmen even gave them meals last night.”

The others, he said, “were tortured.”

It was not immediately clear whether the attackers had a specific goal, and Bangladesh authorities would not say if they had made any demands.

The Islamic State group claimed responsibility, saying it targeted the citizens of “Crusader countries” in the attack. It was not immediately clear if its leadership in Syria and Iraq was involved in planning the attack. The Amaq news agency, affiliated with ISIS, also posted photos purportedly showing hostages’ bodies, though the authenticity of the images could not be confirmed.

The government did not directly comment on the ISIS claim but has denied in the past that the extremist group has a presence in Bangladesh.

On Saturday, Amaq published photos of five smiling young men each holding what appear to be assault rifles and posing in front of a black ISIS flags whom the agency identified as the attackers, according to the SITE Intelligence Service, which monitors jihadi online activity. They were identified by noms de guerre indicating they were all Bangladeshis.

The 20 hostages killed included nine Italians, seven Japanese, three Bangladeshis and one Indian, government sources said, as details of the bloodshed began trickling from other capitals worldwide. The White House confirmed Saturday that a U.S. citizen was among the hostages killed, but did not release any further identification.

Ten of 26 people who were wounded Friday night when the militants opened fire were in critical condition, and six were on life support, according to hospital staff. The injuries ranged from broken bones to gunshot wounds. Hospital staff refused to provide any details of their condition on Saturday.

In the end, paramilitary troops managed to rescue 13 hostages.

The commandos launched the morning rescue operation after the attackers did not respond to calls for negotiation, Masud said.

The commandos killed six of the attackers and recovered explosive devices and sharp weapons from the scene, said Chowdhury of the Army Headquarters.

The audacious attack came during Ramadan, when devout Muslims fast during the day and eat after dark.