Dozens of foreign hostages have been freed after Saudi commandos stormed a compound where they were being held.
Saudi special forces surrounded the compound
About 40 commandos jumped from helicopters onto the roof of the building in the eastern city of Khobar.
Two militants were killed and others arrested, security sources said, but two are reported to have escaped.
An adviser to the Saudi ambassador in Britain has told the BBC that commandos went in after the militants started killing hostages.
Jamal Kashokji told the BBC's Newshour programme that the bodies of nine hostages were found on the premises when forces went in.
One man, who said he was among 25 hostages freed in the dawn raid, told AFP news agency the militants had slit the throats of nine captives.
"The nine had their throats cut by the kidnappers when they tried to escape at night by the stairs," said Nijar Hijazin, a Jordanian computer engineer.
A statement purported to be from an al-Qaeda-linked group and posted on an Islamic website, said its militants had "slaughtered" an Italian and a Swedish hostage.
The claim could not be verified but was consistent with what Mr Hijazin told AFP. He said Asians were also among the dead.
An Italian cook has been confirmed dead, but it is not clear whether he was one of the hostages or whether he was shot on Saturday.
Saudi security officials flashed victory signs as scores of residents and hostages streamed out of the Oasis housing compound at the end of the rescue operation.
Some of the freed hostages were taken to hospital. Others were being treated at the compound.
"Some hostages had fainted, some were dehydrated and some had suffered panic
attacks," the compound manager told Reuters.
The crisis began on Saturday, when the gunmen went on a shooting spree in Khobar.
They first attacked company offices, killing a number of Westerners - including an American and a Briton.
The body of one Westerner was then tied to a car and dragged through the streets.
The number of victims in Saturday's attacks is unclear - at least 10 people are known to have been killed but some reports put the death toll at 16.
The militants then moved to the Oasis compound, where they took a number of people hostage.
They apparently tried to separate the Muslims from the non-Muslims, releasing five Lebanese nationals.
The gunmen were believed to be holding the hostages on the top floor of the six-storey building. Saudi forces entered the building from the roof after reports of booby traps on the levels below.
The Saudi ambassador to the US, Prince Bandar bin Sultan, told the BBC that the authorities had to take action when militants began doing "evil things" to the hostages, including holding a gun to a child's head.
Prince Bandar told US television that Saudi forces had rescued seven American hostages overnight, two of whom were wounded.
An earlier statement purporting to come from an al-Qaeda-linked group claimed responsibility for the attack.
The message from the al-Quds Brigade, which said Americans would not be allowed to steal Saudi Arabia's riches, was carried on an Islamic website.
The incident is the latest in a series of attacks on the kingdom's oil industry - the world's largest.
BBC Middle East correspondent Paul Wood says that with oil at more than $40 a barrel, the attack is bad news for the world's economy.
He adds that by terrifying foreign workers in the oil industry, the militants are also undermining the ruling Saudi royal family - one of their stated aims.
Arab TV pictures showed the troops dropping onto a rooftop
Saudi Arabia's de facto ruler, Crown Prince Abdullah, said militants would not be allowed to undermine the country's economy.
The US embassy has reiterated its call to US citizens to leave Saudi Arabia, while Britain repeated a warning to its citizens to avoid all but essential travel to the country.
Khobar, 400km (250 miles) north-east of Riyadh, is one of the centres of the Saudi oil industry, in which foreigners play a key role.
In early May, five foreigners were killed in an attack on a petrochemical site in the city of Yanbu.
The Saudi government launched a high-profile assault on militants following a triple suicide bombing in Riyadh last May, which killed 35 people including nine bombers.