Updated

COPENHAGEN, Denmark -- Four men who planned a shooting spree at the office of a Danish newspaper that published cartoons of the prophet Muhammed were found guilty of terrorism Monday and sentenced each to 12 years in prison.

The men were arrested in late December 2010 just hours before authorities say they planned to carry out a violent attack on the Jyllands-Posten's offices in Copenhagen.

The Glostrup City Court handed down prison sentences to Mounir Ben Mohamed Dhahri, Munir Awad, Omar Abdalla Aboelazm, and Sabhi Ben Mohamed Zalouti.

The men, Swedish residents of North African and Mideast origin, had been under surveillance by Swedish and Danish intelligence agencies at the time but denied the charges during the trial. The four gave conflicting explanations about the purpose of their journey, which included New Year celebrations in the Danish capital and travel in Sweden.

Surveillance recordings played during the trial showed the four men meeting in Stockholm and discussing martyrdom, the Jyllands-Posten newspaper and how they should kill as many people as possible inside the building housing the paper and take one hostage. The recordings also revealed them discussing what to do about women and children, whose lives they were apparently going to spare.

At a prayer service in Denmark before their arrest, the men were heard on a surveillance tape saying "when you meet the infidels, cut their throats."

The prosecutor claimed that Mounir Dhahri, 46, was the mastermind. Prosecutors say that Dhahri, a 46-year-old Tunisian citizen with a Swedish residence permit, disappeared for two years in 2008-2010 and is believed to have received terror training in the Waziristan region of Pakistan. Dhahri denied this and said he traveled in Europe and Turkey.

The group left Stockholm Dec. 28, 2010 and headed south to Copenhagen, where three of them were arrested the next morning. During the trip, Zalouti left the car and returned to Stockholm, where he was arrested by police the same day.

Danish police found the men in possession of two automatic weapons, 122 rounds, and more than $20,000 in cash.

During the trial, the prosecution presented evidence suggesting that Aboelazm, 32, was arrested in Somalia and Pakistan in 2007 and 2009 on suspicion of terrorist activities, but he was never charged and eventually released.

Denmark has been in the crosshairs of Islamist terror groups since the publication of cartoons depicting the Prophet Muhammad in 2005, an act that offended many Muslims and sparked demonstrations and rioting in many Muslim countries.

Last year, a Somali man living in Denmark was convicted of terrorism and sentenced to 10 years in prison after using an ax to break into the home of one of the cartoonists in 2010. A Chechen-born man was also sentenced last year to 12 years in prison for preparing a letter bomb that exploded as he was assembling it in a Copenhagen hotel in 2010. Last week, two Danish brothers of Somali origin were arrested for allegedly plotting an attack to avenge the cartoons' publication.