Ten people, including a Canadian woman, have been killed after gunmen ambushed police in a series of attacks in Jordan.
One of the attacks targeted a Crusader castle popular with tourists, killing seven officers, two civilians and the Canadian victim, Linda Vatcher.
Several armed men were barricaded inside the castle in Karak, a town in central Jordan about 87 miles south of the capital Amman, after night fell, surrounded by Jordanian special forces.
At least 34 people, including two foreigners, were wounded in Sunday's violence, one of the bloodiest attacks in Jordan in recent memory.
Several hours later security officials announced that the operation had ended and four gunmen were killed. They said large amounts of weapons had been seized and troops continued to search the area.
They made no reference, however, to news reports that at one point the attackers had held hostages.
The shootings were the latest in a series of attacks that have challenged the pro-West kingdom's claim to be an oasis of calm in a region threatened by Islamic extremists.
A witness said attackers immediately targeted tourists when they reached the castle.
"Four gunmen got out of their car" at the castle, said Wasfi al-Habashneh. "They opened fire at the Canadian tourists. The woman was killed, the other Canadian tourist escaped and hid behind a car and one of the children was injured."
Mr al-Habashneh said the attackers also targeted other people. Security forces "engaged with the gunmen and cornered the gunmen at the castle gate", he said.
The killing of the Canadian tourist could further hurt Jordan's embattled tourism sector, which has declined sharply since the Islamic State group seized large parts of neighbouring Syria and Iraq two years ago.
Canada's global affairs spokesman John Babcock said Ms Vatcher was a former teacher from Burgeo, Newfoundland. Her son Chris was injured in the attack.
"Canadian officials in Amman are actively working with local authorities to gather additional information and are providing consular assistance to Canadians at this difficult time," he said.
The Canadian embassy in Amman issued an alert warning Canadians to avoid travel to Karak.
There was no immediate claim of responsibility for the attacks in and near Karak.
The chain of events began when a police patrol received reports of a house fire in the town of Qatraneh in the Karak district, Jordan's Public Security Directorate said.
Officers responding to the call came under fire from inside the hous. Two policemen were wounded and the assailants fled in a car.
In another attack, gunmen fired on a security patrol in Karak, causing no injuries.
Armed men also opened fire on a police station at Karak Castle, a Crusader fort, wounding members of security forces. The statement said five or six gunmen were believed to be trapped inside the castle.
In all, seven members of the security forces, two local civilians and the Canadian woman were killed, security officials said. Fifteen members of the security forces, 17 civilians and two foreign nationals were injured.
Jordan faces home-grown extremism, with hundreds of Jordanians fighting alongside other IS militants in Iraq and Syria and several thousand more supporting the extremist group in the kingdom.
Jordan is a key US ally, and a member of a US-led military coalition fighting IS.
Over the past year, gunmen have carried out several attacks on members of the Jordanian security forces and foreign trainers. Earlier this year Jordanian security forces engaged in a deadly shoot-out with suspected IS sympathisers in a northern town.
In the most recent incident, three US military members were killed in a shooting outside an air base in southern Jordan in November. They were in the country on a training mission and came under fire while driving into the base.
Barb Rhymes, a cousin of widow and mother-of-two Ms Vatcher, 62, said she had been visiting her son in Jordan where he worked.
"She was very friendly, outgoing. She was nice to everyone. A friend to all," Ms Rhymes said from Burgeo, a remote town of 1,400 people on Canada's east coast.
"It's devastating. It has hit the town hard. My mind is not there right now. She was a beautiful person."