Two guards have been shot dead and three others injured when a man drove up to the gate of the Saudi royal palace in Jeddah and began shooting, the interior ministry says.
Royal Guards killed the gunman, who was identified in the statement as Mansour al-Amri, a 28-year-old Saudi national.
The attack occurred on Saturday morning 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 Mr Amri's possession.
Mr 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.