Saudi security forces have been on high alert because of frequent attacks coming from Yemen, where a Saudi-led coalition is participating in that country's civil war.
A Yemeni rebel group has fired dozens of ballistic missiles at Saudi cities and towns over the past few years, including towards Riyadh. In March, missile fragments plunged into a house in Riyadh and killed an Egyptian construction worker.
The Yemeni rebels, known as the Houthis, have also claimed to have carried out armed drone attacks on the Saudi-led coalition in Yemen, as well as on Saudi territory.
Saudi Arabia is also in the midst of a sweeping social and economic transformation carried out by Crown Prince Mohammed bin Salman. The changes have included the easing of social restrictions - like the prohibition on women driving - but also a determined consolidation of power under Prince Mohammed that has sidelined rivals and landed dissenting voices in jail.
In videos purportedly recorded in Riyadh that were shared on social media, the sounds of heavy barrages of gunfire could be heard. The authenticity of the videos could not be independently confirmed.
A Saudi official told the Reuters news agency that King Salman was not in his palace when the shooting took place.