Two Saudi guards were shot dead and three others injured 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 carried by state news.
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.
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.
Security forces 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.