The deaths come amid a growing war of words between Saudi Arabia and the militant group Islamic State, which called for attacks in the kingdom. But it may also raise tensions with Iran over the execution of prominent Shi'ite cleric Nimr al-Nimr.
Tehran warned last year that executing Nimr would "cost Saudi Arabia dearly".
Most of those executed were convicted of leading or carrying out a series of al Qaeda attacks in Saudi Arabia after 2003, but they also included some members of the Shi'ite minority convicted of attacks on police during protests from 2011-13.
In a statement issued on state television and other official media, the Interior Ministry named the 47 dead men and listed crimes that included both involvement in attacks and embracing jihadist ideology.
The simultaneous execution of 47 people on security grounds was the biggest mass execution for such offences in Saudi Arabia since the 1980 killing of 63 jihadist rebels who seized Mecca's Grand Mosque in 1979.
Saudi Arabia in 2015 suffered a series of further bombing and shooting attacks by jihadist militants sympathetic to Islamic State group. Those attacks killed dozens, increasing pressure on Riyadh to show it was taking strong action.
"There is a huge popular pressure on the government to punish those people. It included all the leaders of al Qaeda, all the ones responsible for shedding blood. It sends a message," said Mustafa Alani, a security analyst close to the Interior Ministry.
The conservative Islamic kingdom, which usually executes people by public beheading, detained thousands of militant Islamists after a series of al Qaeda attacks from 2003-06 that killed hundreds, and has convicted hundreds of them.
However, it also detained hundreds of members of its Shi'ite minority after protests from 2011-13, during which several policemen were killed in shooting and petrol bomb attacks.
At least three other Shi'ites were executed alongside Nimr, including Ali al-Rubh, whom relatives said was a juvenile at the time of the crime for which he was convicted, Mohammed al-Shayoukh and Mohammed Suwaymil.
Activists in the Shi'ite district of Qatif have warned of possible protests in response to the executions. However, Nimr's brother, Mohammed al-Nimr, said he hoped any response would be peaceful.
The Interior Ministry statement began with Koranic verses justifying the use of execution and state television showed footage of the aftermath of al Qaeda attacks in the last decade. Saudi Grand Mufti Sheikh Abdulaziz Al al-Sheikh appeared on television soon after to describe the executions as just.
The executions are Saudi Arabia's first in 2016. At least 157 people were put to death last year, a big increase from the 90 people killed in 2014.
Banner / Thumbnail : Reuters