Seven police officers, two Jordanian civilians and one Canadian tourist were killed Sunday when gunmen staged a series of attacks on police patrols and a historic castle in the heart of the southern city of Karak. Four gunmen were also killed.

According to Jordanian police, at least 28 others were injured, and security sources confirmed that as many as 14 people, mainly foreign tourists, were held hostage by the gunmen.

By evening, according to local media reports, Jordanian special forces had freed them after a five-hour standoff.

During the attacks, as many as 10 gunmen holed themselves up in the Karak Crusader castle, a major tourist attraction and one of the most complete Crusader castles in the world.

Mosques’ loudspeakers across the city called on residents to flee as security operations intensified.

(Reuters)

Eyewitnesses reported chaos as thousands fled businesses and homes to the surrounding countryside.

Jordan’s security forces announced late Sunday an end to the showdown. Jordanian authorities said security forces arrested four gunmen and are completing final sweeps of the historic castle.

In addition to the death toll, authorities said 11 Jordanian police officers were injured in the 10-hour attack, as well as 17 civilians, among them several foreign tourists.

An investigation into a rented apartment 25 miles east of Karak used by the gunmen, who are believed to be part of an Islamic militant “sleeper cell,” revealed dozens of automatic weapons, explosives and suicide bomber vests, authorities said in the statement.

Security officials said that the gunmen were a mix of ­non-Jordanian Arab nationals and Jordanians.

No group has claimed responsibility.

The U.S. Embassy in Amman issued a statement to citizens warning of an “active shooter” in Karak, 80 miles south of the capital, and urged citizens to “avoid that area for the time being.”

Jordan has long been hailed as an oasis of stability and security in the violence-plagued Middle East, with wars and terrorist havens near its borders with Syria to the north and Iraq to the east.

But the image of stability is being eroded. Sunday’s attack marked the fourth deadly targeting of Jordanian security and army personnel this year.

In March, a cell of Islamist militants linked with the Islamic State engaged in a shootout with police in the northern city of Irbid, leaving one police officer and seven gunmen dead. A gunman killed five General Intelligence Department officers in Baqaa refugee camp, a few miles north of the capital, in June. Later in June, Islamic State militants executed a truck-bombing, killing seven Jordanian soldiers stationed near a makeshift refugee camp along the Jordan-Syria border.

In November, a Jordanian officer opened fire and killed three U.S. military trainers at an air base near Jafr used for training Syrian rebels — although the motives behind the shooting are still unclear.

Although the Islamic State has not announced a branch in Jordan, the group has a force of 1,400 known as the Khalid ibn al-Walid Army a few miles away from the Jordan-Syria border near the city of Deraa.

Security officials privately said the Islamic State likely has at least a “sleeper cell” in the country.

Although Jordan is a major ally in the war on the Islamic State, 3,000 Jordanians fight under its banner, experts said, making up one of the largest foreign contingents in the extremist group.

Jordanian officials have repeatedly expressed their concerns of the threats to the kingdom should these fighters return home.

Read more:

3 U.S. military trainers killed in gunfire by security units at Jordan base

Jordan to use cranes to send aid to 75,000 Syrian refugees across border

Reinvention of Jordan’s Muslim Brotherhood involves women — and Christians

Today’s coverage from Post correspondents around the world

Like Washington Post World on Facebook and stay updated on foreign news