One of five men arrested this week over a foiled plot to massacre staff at a Danish newspaper had twice been detained abroad suspected of terror links, the foreign ministry and media said Friday. Munir Awad, a 29-year-old Swede born in Lebanon, had publicly thanked Swedish intelligence agency Saepo for obtaining his release from Somalia when he was detained there three years ago, they said. 'We know Saepo brought us home and we are very grateful,' he told a newspaper at the time. Swedish foreign ministry spokesman Anders Joerle confirmed Awad's previous arrests and that Sweden had intervened on his behalf. 'Awad was arrested in Somalia by Ethiopian troops. That was in 2007. He was arrested in Pakistan in 2009,' he told selfnews. 'What we did was insist that he either should be tried or set free.' Awad was one of five men arrested Wednesday for hatching what Danish officials called a plan to 'kill as many people as possible' in an assault on the Jyllands-Posten daily. The paper published in September 2005 a dozen cartoons of the Muslim prophet that triggered violent and sometimes deadly protests around the world. Four men -- including Awad and two other Stockholm-based men -- were arrested in suburbs of Copenhagen and one was arrested north of the Swedish capital. The man arrested in Sweden was named in court as Sahbi Zalouti, a 37-year-old Swede of Tunisian origin. He was on Thursday remanded in custody for two weeks. Joerle told selfnews Friday that Zalouti had been arrested in Pakistan in 2009 for entering the country illegally, but said it remained unclear if he was connected to Awad. Danish intelligence agency PET only gave the age and citizenships of the three Stockholm-based men -- who have been remanded in custody in Denmark -- but media has identified them as Awad, 44-year-old Tunisian Mounir Dhahri and 30-year-old Swede Omar Abdalla Aboelazm. Media reported that the four men living in Sweden figured among 200 violence- prone Islamist extremists in the country that Saepo said in early December it was keeping tabs on. The agency said the four had been under surveillance for months. PET said the fourth man arrested near Copenhagen was a 26-year-old Iraqi asylum seeker. Media named him as Abdullah Muhammed Salman. He was was freed Thursday but is still suspected of being connected to the plot. He denied knowing about any terror plans and told tabloid Ekstra Bladet he met two of his suspected accomplices at a mosque in Stockholm and had helped the trio find a flat near Copenhagen. When Awad was arrested in Somalia in 2007, he was travelling with his then 17 -year-old pregnant wife Safia Benaouda, who is the daughter of the head of Sweden's Muslim Council Helena Benaouda, Swedish daily Svenska Dagbladet reported. When he was arrested in Pakistan in August 2009, he was with Benaouda and their son as well as Mehdi Ghezali, a Swede who had spent two years in the US detention centre at Guantanamo Bay, Joerle said. The Aftonbladet daily reported Awad had shared a Stockholm apartment with two Swedes of Somali origin found guilty by a Swedish court in December of 'planning terrorist crimes' in Somalia and sentenced to four years in prison. The court said they were members of the Islamist movement Al-Shebab, which has declared allegiance to Osama bin Laden's Al-Qaeda network. Jyllands-Posten and Swedish tabloid Expressen reported Friday that David Headley, who helped plan the 2008 Mumbai attacks, had been in contact with a Stockholm-based possible mastermind of the foiled plot, who was not among the men arrested. 