RIYADH, Saudi Arabia -- Saudi Arabia's top cleric said Tuesday that extremism and the ideologies of groups like the Islamic State and al Qaeda are Islam's No. 1 enemy and that Muslims have been their first victims.

Grand Mufti Sheik Abdul-Aziz Al-Sheik also said in his public statement that terrorism has no place in Islam, and that the danger of extremists lies in their use of Islamic slogans to justify their actions that divide people.

"These foreign groups do not belong to Islam and Muslims adhering to it," he said, adding that unity around the word and rank of Saudi Arabia's king and crown prince is necessary to avoid the type of chaos seen elsewhere in the region.

King Abdullah has been pressing clerics to publicly condemn Islamic extremist groups since the government made it illegal for citizens to fight in conflicts abroad. Clerics who do not condemn terrorism in traditional Friday sermons could face penalties, such as having their licenses to preach revoked.

Local media have reported that the Saudi Interior Ministry may require clerics to pass a security screening before they can preach, and that around 3,500 clerics in Saudi Arabia have been dismissed since 2003 for their sermons.

The Islamic State group's advances in Iraq and Syria have heightened security concerns in neighbouring countries like Saudi Arabia. They have also prompted a number of articles and discussions in the local press about how to confront the spread of "Takfiri" ideology, which shuns anyone who does not adhere to a stringent interpretation of Islam. Saudi Arabia follows a puritanical interpretation of Islam known as Wahhabism.

A decade ago, al Qaeda militants launched a string of attacks in the kingdom aimed at toppling the monarchy. A fierce crackdown by Saudi Arabia's security services forced many militants to flee to neighbouring Yemen, which now has one of the world's most active al Qaeda branches.

Over the past two days, a court in the capital, Riyadh, has sentenced 31 people for their involvement in those attacks, sentencing three to death and the rest to prison. All will be allowed to appeal the verdict.

On Tuesday, the court sentenced two men to death and 15 others to prison on various charges of murder, firing at security forces and plotting to assassinate top officials. They were also found guilty of assaults on residential compounds where foreigners live in Riyadh and the Eastern Province, the official Saudi Press Agency reported.

A day earlier, the court sentenced one man to death and 13 others to prison for their role in killing a foreigner, attacking government buildings and residential compounds and planning an assault on the U.S. and British embassies during the height of those attacks, the official Saudi Press Agency reported.

The men, whose nationalities were not disclosed, were part of an alleged 50-member terrorist cell that faces a host of charges, including plotting to assassinate senior government officials and smuggling heavy weapons into the kingdom from Iraq. They are also charged with fighting in conflicts abroad, firing at Saudi security officers and disobeying the king.

In the first verdict issued Monday night, the court found the 14 men guilty of being involved in an attack on a foreigner who was stopped at a fake checkpoint, the state news agency said. Impersonating security officers, the militants drugged the foreigner to abduct him, then beat him to death before beheading him, the agency said.

The Arabic language newspaper Al-Sharq Al-Awsat reported that the man they were charged with killing is Paul Marshall Johnson, a 49-year-old American from New Jersey who had worked in the kingdom for more than a decade and was working on Apache attack helicopter systems for Lockheed Martin at the time of his kidnapping and death in 2004.

The militants had threatened to kill him if the kingdom did not release its al Qaeda prisoners. After Saudi authorities refused to comply with their demands, the gruesome photos of his severed head were posted on the Internet, prompting strong condemnation from then-President George W. Bush.

Two others among the 50 defendants on trial will be given more time to submit additional evidence while a ruling on the rest of the cell's 17 alleged members is expected soon, the Saudi news agency said. It did not say if all 50 suspected cell members were in custody, or whether some were being tried in absentia.

A senior government official contacted by The Associated Press declined to give further details.

Batrawy reported from Dubai, United Arab Emirates.