After residents in Saudi Arabia’s capital reported hearing rare bursts of gunfire on Saturday evening, followed by videos of heavy shooting that circulated on the Internet, the Saudi government said it had an explanation: Someone had flown a recreational drone, without authorization, and security forces had shot it down.  

 A government statement said that guards at a checkpoint in Riyadh, the capital, observed the drone shortly before 8 p.m., in the Al-Khozama neighborhood, where a palace belonging to King Salman, the Saudi monarch, is located. The security forces “dealt with it according to their orders,” the statement said. 

 “It was a small remote-controlled toy airplane that came into restricted airspace and was immediately shot down,” said a Saudi official who requested anonymity because he was not authorized to speak to the news media. 

 A retired government official who lives in the neighborhood said that he heard gunfire, but it had only lasted a short time. “It went on maybe for two or three minutes,” he said, declining to be named. “It is quiet now,” he added.

 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 toward 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 on Saturday 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.

Morris contributed to this report from Amman, Jordan.