In the ensuing gun battle with Saudi security forces, 12 people -- five non-American staff, three attackers and four members of the Saudi National Guard -- were killed.
Two attackers, who were wounded, were arrested, the Saudi interior ministry said.
Shaken Westerners start leaving Saudi
Saudi hostage drama ends, 8 Indians killed
The US embassy in Riyadh said all Americans had been accounted for.
The US has asked non-emergency staff and their family members at its embassy in Riyadh and consulates in Jeddah and Dahran to leave the country and advised Americans to refrain from travelling to the region.
An interior ministry statement carried by the official Saudi Press Agency, said a "stray bunch" -- a reference to Islamic militants -- threw explosives at the gate of the consulate and entered the complex.