Saudi commandos stormed a compound where Islamic extremists had seized foreign oil workers after the gunmen began executing the hostages early Sunday, Saudi officials said. About 50 hostages were rescued, but one American and 21 other people were killed in the Persian Gulf city of Khobar, 250 miles northeast of Riyadh, the capital.

Saudi officials said they captured the ringleader of the gunmen, adding that he was shot and wounded while trying to escape. They did not identify him by name but said he was among the 25 most wanted terrorism suspects in the kingdom.

A group allied with al Qaeda asserted responsibility for the attack and released statements indicating that the plot was an attempt to destabilize world oil markets and drive a wedge between Saudi Arabia and the United States.

The attack will have no direct impact on petroleum supplies, analysts said, but it showed that extremists are capable of striking this oil-producing region and is likely to intensify concerns about the vulnerability of markets to a supply disruption. [Story, Page A18.]

There were conflicting reports on the total number of gunmen and what happened to them. Three gunmen escaped after they commandeered a car and used some of the hostages as shields, according to a Saudi security official. Other officials said there were as many as seven assailants.

It was the fourth time in 13 months that Islamic extremists have launched deadly attacks on foreign targets in the desert kingdom.

Witnesses said the gunmen went room to room inside the walled compound searching for foreigners to kill or kidnap, but tried to leave Muslims unharmed.

The dead included citizens from at least 10 countries. In addition to the American, they included eight Indians, three Saudis, three Filipinos, two Sri Lankans, a Briton, an Egyptian, an Italian, a Swede and a South African, the Saudi Interior Ministry reported. Twenty-five people were injured, the ministry said.

Among the roughly 250 people who were trapped inside the compound were two members of the U.S. military who lived there, a Saudi security official said on condition of anonymity. The military officers were rescued by a Saudi special forces team, the official said.

Jamal A. Khashoggi, an adviser to the Saudi ambassador to London, said in a telephone interview that Saudi forces rushed the gunmen after they started to execute some of the hostages on the sixth floor of the Oasis Residential Resorts, a complex that caters to foreign oil workers and their families. "The terrorists started killing them, and that's when Saudi security stormed the building," he said.

Television footage from Khobar showed Saudi forces landing from helicopters on the roof of the resort building. Several hours later, commandos stormed the sixth floor and freed most of the 50 or so hostages that the gunmen had been holding there, but only after defusing bombs laid as booby traps on two of the floors below, according to reports on Arab television channels.

A Saudi group allied with al Qaeda asserted responsibility for the attack, posting statements on Islamic Web sites that described in gruesome terms the deaths of an American, a Briton, a Japanese and an Italian. An audio recording posted with one of the statements blamed the Saudi government for providing "America with oil at the cheapest prices according to their masters' wish, so that their economy does not collapse."

A Japanese Foreign Ministry official, however, said no Japanese citizen was among those killed, the Reuters news agency reported.

The speaker on the recording identified himself as Abdulaziz Muqrin, a leading al Qaeda operative in Saudi Arabia

Until last year, the Saudi government has played down evidence that it faced a growing threat from Islamic radicals who wanted to sever ties with the West. Since the spate of deadly attacks erupted, Saudi security forces have tried to crack down on such groups, rounding up hundreds of suspects and issuing a list of wanted al Qaeda sympathizers.

"Their intent . . . is to frighten, it is to murder people, it is to try to cripple the Saudi economy and the world economy," Nail Jubeir, a spokesman for the Saudi Embassy in Washington, told CNN. "They're trying to play on that split of culture, split of civilization, but it's not going to work."

Oil and gasoline prices have soared in recent weeks, and the Saudi government has responded by promising to increase production to meet rising worldwide demand.

Despite the recent attacks against foreign oil workers, Saudi officials have tried to reassure world energy markets that their pipelines, terminals and oil processing center are well-guarded and not vulnerable to attack.

Nawaf Obaid, a Riyadh-based consultant to the Saudi royal family, said in an article published this month in Jane's Intelligence Review that the risk of a disruption to the flow of oil was "very low."

"Saudi Arabia takes the security of its oil facilities extremely seriously," Obaid wrote. "At any one time, there are up to 30,000 guards protecting the country's oil infrastructure, while high technology surveillance and aircraft patrols are common."

Khashoggi, the Saudi adviser in London, acknowledged that the government was originally taken aback by the persistence of the insurgents. Security has been stepped up, he said, but there is only so much that the kingdom could do to prevent attacks.

"All of us underestimated the threat," he said, referring to the Saudi and Western governments. "The oil installations are very much protected. But these people are attacking soft targets, and soft targets are available. There are thousands of foreigners all over the kingdom."

Sherard Cowper-Coles, the British ambassador to Saudi Arabia, told reporters in Khobar that the danger from extremist groups remained high. "We believe further attacks may be in the final stages of preparations," he said, though he did not give details. At least one Briton, an oil executive, Michael Hamilton, 61, was killed in the attack, he said. Witnesses said earlier that the body of a Briton was dragged through the streets, the Associated Press reported.

The attack began just after dawn Saturday, when the gunmen entered a walled office compound and overpowered two guards. The gunmen killed some oil company employees on the spot. They then started seizing hostages, taking them to the sixth floor of the high-rise building in the luxury residential compound. Saudi commandos occupied floors above and below but did not rush the gunmen until the executions began, government officials said.

A body is carried from the Oasis complex in Khobar, Saudi Arabia, where one American and 21 others were killed in an attack. It ended when Saudi commandos raided the compound, which caters to foreign workers, and rescued about 50 hostages.Saudi forces are dropped onto the roof of a building at the Oasis Residential Resorts, where hostages were on the sixth floor.