Security forces seize Kalashnikov rifles and petrol bombs that were in shooter's possession
Two Saudi guards were shot dead and three others wounded on Saturday morning when a man drove up to the gate of the royal palace in Jeddah and began shooting, the interior ministry said in a statement.
"An outpost of the royal guard came under fire by a person who got out of a Hyundai car," the ministry said in a statement carried by the official Saudi Press Agency.
"He was immediately dealt with and his cowardly act also resulted in the martyrdom" of two royal guards, it added.
Royal guards killed the gunman, who was identified in the statement as Mansour al-Amri, a 28-year-old Saudi national.
The attack occurred at a checkpoint outside the western gate to the Peace Palace in Jeddah, where the royal family conducts official business during the summer months.
Saudi King Salman is currently outside the kingdom on a state visit to Russia.
Palace guards killed in Saudi shooting in Jeddah https://t.co/XzQjrl4D1Q
— BBC News (World) (@BBCWorld) October 7, 2017
The statement did not elaborate on the whereabouts of his son, Crown Prince Mohammed bin Salman, although recent state news reports have placed him in Jeddah.
The US embassy in Saudi Arabia had earlier cautioned its citizens over reports of the attack.
"Due to the possibility of ongoing police activity, American citizens are advised to exercise caution when travelling through the area," the embassy said in a brief statement.
The warning comes after the Saudi police raided hideouts of a "terror" cell linked to the Islamic State (IS) group this week, killing two people and arresting five others, according to the national security agency.
The State Security Agency said police raided three hideouts in the capital Riyadh and exchanged gunfire at one of them, the SPA news agency reported on Thursday.
Security forces on Saturday seized Kalashnikov rifles and petrol bombs that had been in Amri's possession.
Amri did not have a criminal record or any known connection to extremist groups, said Interior Ministry spokesman Mansour al-Turki, speaking by phone to al-Arabiya television.
An investigation was underway to determine his motive for the attack, said Turki.
Since late 2014, IS has claimed a series of bombings and shootings against Shias and security forces in the Sunni-majority kingdom.
Saudi Arabia is a member of the US-led international coalition that has been battling the Sunni extremist group in Syria and Iraq.