* Aims to cut security risk of Saudis returning from Syria
* Up to 20 years in prison for Saudis who join foreign wars
* Separate counter-terrorism law stifles dissent -activists (Adds detail, concerns about new anti-terrorism law, context)
RIYADH, Feb 3 (Reuters) - Saudi Arabia will jail for 3-20 years any citizen who fights in conflicts abroad, according to a royal decree released on Monday, in an apparent move to deter Saudis from joining rebels in Syria and then posing a security risk once they return home.
Saudi Arabia's Islamic religious authorities have previously spoken out against Saudis joining Islamist militants involved in Syria's civil war, but the Interior Ministry estimates that around 1,200 Saudis have gone there nonetheless.
The decree underscored concern about young Saudis hardened by battle against Syrian President Bashar al-Assad coming home to target the ruling Al Saud royal family - as happened after earlier wars in Afghanistan and Iraq.
Saudi Arabia is the world's No. 1 oil exporter and a mainstay ally of the United States in the Middle East.
"(Saudi leaders) have to be concerned about Syria. They're probably mindful about what happened in Afghanistan and the people who went there and later came back to cause problems," said Robert Jordan, U.S. ambassador to Riyadh from 2001-03.
Major General Mansour Turki, Saudi Arabia's security spokesman, told Reuters on Sunday that 200-300 citizens had returned from Syria and would be put through the kingdom's rehabilitation programme for militants.
The decree also said Saudis who join, endorse or give moral or material aid to groups it classifies as terrorist or extremist organisations, whether inside or outside the country, would face prison sentences of between five and 30 years.
The announcement came quickly on the heels of the publication on Friday of a new anti-terrorism law that has been condemned by rights activists as a tool to stifle dissent.
The new decree said a committee would be set up to determine which groups would be outlawed, but it could help Riyadh target two movements it sees as particularly dangerous - Egypt's Muslim Brotherhood and the Lebanese Shi'ite Hezbollah.
"Syria is probably the main factor at play here. But as this decree comes on the heels of the new counterterrorism law it could also presage prosecutions for Saudis accused of glorifying movements elsewhere, potentially including Hezbollah or even the Egyptian Muslim Brotherhood," said Jane Kinninmont, senior research fellow at Chatham House in London.
Riyadh fears the Brotherhood, which espouses a conservative Sunni doctrine that challenges the Saudi principle of dynastic rule, has tried to build support inside the kingdom since its rise to power in Egypt via a free election in 2012 and subsequent overthrow by the army following mass unrest.
When Brotherhood supporters protested against Egypt's military-backed government last summer following the overthrow of Islamist president Mohamed Mursi, it branded the unrest as "terrorism" and sedition.
Saudi authorities have also accused Hezbollah of acting as an Iranian proxy throughout the Middle East and last year joined other Gulf Arab countries in calling for sanctions against it. Riyadh has accused Iran of supporting protests among its Shi'ite minority in Eastern Province.
The anti-terrorism law published in Riyadh's official gazette on Friday says terrorist crimes include any act that "disturbs public order, shakes the security of society, or subjects its national unity to danger, or obstructs the primary system of rule or harms the reputation of the state".
Over the past decade Saudi Arabia has imprisoned thousands of people convicted of working with al Qaeda after the Sunni Islamist militant group staged attacks inside the kingdom from 2003-06 that killed hundreds.
Rights groups have said some of those Riyadh imprisoned on those charges had merely called for political change in a peaceful manner, a charge the government has repeatedly denied.
In the past year Saudi authorities have also been criticised by international rights groups for jailing several prominent activists on charges ranging from setting up an illegal organisation to damaging the reputation of the country.
When an earlier draft of the new law was made public by rights group Amnesty International in 2011, Saudi Arabia said it was revising the text to make it less severe.
The new law applies to both Saudis and foreigners inside and outside the kingdom, and allows the authorities to hold suspects incommunicado for up to 90 days, or for longer periods with the approval of a special criminal court.
A spokesman for the Shoura Council said in 2011 the law would be made compatible with sharia (Islamic law) and would not violate citizens' rights or existing statutes.
Saudi human rights activist Walid Abu al-Khair criticised the law, saying it was intended to "combat peaceful demands". "It shapes a first-rate threat to all activists and it is meant to strangle freedom of expression," Abu al-Khair told Reuters.
(Reporting by Angus McDowall and Yara Bayoumy; Editing by Mark Heinrich)