A Saudi court sentenced a Chadian and an Egyptian to death on Monday while several other people were jailed up to 33 years for "terrorist" related offences, official media said.
A Saudi Arabian accused also received the death sentence from the special court in Riyadh, the Saudi Press Agency reported.
Those jailed included five from the African nation of Chad, a Nigerian, a Yemeni and a Palestinian, along with Saudis, the agency said.
It did not say when the offences occurred but the accused were charged with opening fire at a Khaldiya district apartment block in the holy city of Mecca.
In June 2003 the interior ministry announced that five suspects preparing an "imminent" attack were shot dead and two security officers killed during a raid on the Khaldiya building.
Signup to our newsletter and follow us on Facebook and Twitter!
It said at the time that several suspects including Chadians, an Egyptian and a Saudi were arrested.
At their trial in Riyadh, the accused were also charged with training "at Al-Qaeda camps", planning to kidnap and kill VIPs, and other offences, the Saudi Press Agency said.
They can appeal the court's decision within 30 days.
Authorities in 2011 established specialised tribunals to try Saudis and foreigners accused of belonging to Al-Qaeda or of involvement in deadly attacks in the kingdom from 2003-2006.
These included assaults on housing compounds where foreigners lived and led to a crackdown.
Since late September Saudi Arabia and other Arab states have taken part in or given support to US-led coalition air strikes against militants of the Islamic State group in Syria.
Saudi King Abdullah has said that extremism "has nothing to do with Islam."