"The squadron of the martyr Abu Anas al-Shami carried out the blessed Falluja attack by storming one of the bastions of the crusaders in the Arabian Peninsula ... from where the land of the two holy places is ruled ... and spies and traitors dispatched far and wide," the group said in a statement posted on the Ansar al-Sunna website.
The statement's authenticity could not be verified but the organisation has often used the same website to make announcements.
The claim came after Saudi Arabian security forces regained control of the consulate, bringing to an end the bloody assault on the heavily fortified site.
Five workers lay dead after the attack in which insurgents burst through the gates of the tightly guarded compound on Monday morning, sparking a shootout with security forces.
No US nationals were among the dead although two embassy workers were lightly injured.
Three of the attackers were killed and two arrested after hundreds of soldiers and policemen surrounded the compound located in a busy commercial district in the cosmopolitan Red Sea port city, according to Saudi officials.
The al-Qaida statement said only two of its group had died and three had withdrawn to safety after being injured. It also claimed to have killed nine workers and security men.
Saudi Arabian security forces
surrounded the compound
The Saudi interior ministry said 13 people were wounded, including five security officers, but the internet statement said tens of people had been injured.
Witnesses said the attackers hauled down the US flag and set it alight. Saudi television pictures showed a military helicopter hovering over the building, part of which was ablaze. Plumes of smoke could be seen rising into the sky.
It was the first assault by suspected rebels since May and appeared to undermine the Saudi authorities' claims to have broken the back of an insurgency with the killings of key leaders this year, including Abd al-Aziz al-Muqrin, said to have been al-Qaida's leader in the kingdom.
Attackers gained entry by following two diplomatic vehicles into the compound via the main gate, witnesses said.
Gardeners working in the mission said attackers in a white saloon burst in at about 11.15am and began firing.
Abd al-Hamid al-Mutawa, chairman of al-Mutawa Sons & Co, which is contracted to tend the gardens in the complex, told Aljazeera.net his staff had seen the rebels kill a security guard.
"When confronted they [attackers] opened fire immediately, killing one security guard. The other guards returned fire, killing one of the attackers," he said, adding that Saudi forces arrived at the site within 15 minutes of the attack.
All of al-Mutawa's 10 employees at the consulate escaped physically unharmed but in shock, one of them after hiding in a rubbish container for four hours.
A Western executive, quoting officials inside the building, said the attackers threw hand grenades.
"Several men breached US and Saudi security and lobbed one or several grenades at the building," he said.
The attacks occurred in the Red
Sea port city of Jedda
The Saudi Arabian interior ministry issued a television statement after the attackers had been overcome.
"Members of the deviant group this morning threw explosives at the gate of the US consulate in Jedda and then entered the compound," an official said, using the government's language for al-Qaida.
"The security forces dealt with the situation and managed to control it. Three of the attackers were killed and two were arrested after they were wounded."
A Saudi security official said US citizens had evaded harm by fleeing into a fortified safe area in the mission.
In a swift reaction to the attack, US President George Bush said it confirmed that "terrorists were still on the move" and linked them to fighters opposing the US-sponsored interim government in Iraq and elections scheduled to be held in January.
Saudi al-Qaida leader Abd al-Aziz
al-Muqrin was killed this year
"They want us to leave Saudi Arabia, they want us to leave Iraq, they want us to grow timid and weary in the face of their willingness to kill randomly, kill innocent people. That's why these elections in Iraq are very important," he said.
The US embassy in Riyadh and missions in Jedda and Dhahran closed their doors after the attack and an embassy statement said they would remain closed to the public until further notice.
"American citizens in Saudi Arabia are strongly urged to exercise utmost security precautions," it said.
About 170 people, including foreigners, security forces, and suspected insurgents have been killed since the first wave of attacks hit Riyadh 18 months ago.
Insurgents waging a violent campaign against the country's absolute monarchy and its relations with Western nations have been behind the attacks.
In the kingdom's last big attack, suspected insurgents struck at oil companies in the eastern city of Khobar in May. At least 22 foreign workers and seven security men died in that incident.
Rebels have killed several foreigners since then, inviting a Saudi crackdown.
The latest attack follows a lull and had analysts warning that the country was far from safe.
"It shows that despite Saudi claims to the contrary, al-Qaida can still mount operations in the country," said Simon Henderson, a British consultant on the kingdom.
"Worryingly there remains concerns not only about the effectiveness of Saudi security forces but also about their loyalty," Henderson said in London.