COPENHAGEN, Denmark - Police in Denmark and Sweden said they thwarted a terrorist attack possibly hours before it was to begin yesterday, arresting five men they say planned to shoot as many people as possible in a Copenhagen building housing the newsroom of a paper that published cartoons of the Prophet Muhammad.

Four suspects were arrested in the suburbs of Copenhagen, including a Tunisian, a man from Lebanon and an Iraqi asylum-seeker. A fifth suspect, a Swedish citizen of Tunisian origin, was arrested in Sweden. The Danish intelligence service said it seized a submachine gun, a silencer and ammunition.

"An imminent terror attack has been foiled," said Jakob Scharf, head of the Danish Security and Intelligence Service, or PET. Scharf said three of the men were arrested as they left a suburban Copenhagen apartment, "either heading out to carry out the terror attack or to do some kind of reconnaissance."

Scharf described some of the suspects as "militant Islamists with relations to international terror networks." He said more arrests were possible.

Authorities said the arrests followed months of surveillance. Anders Danielsson, the head of Sweden's security police, said officers followed a car rented by three of the suspects from Stockholm to the Danish border.

"We knew that there were weapons in the car," Danielsson said.

Danish intelligence said the group had been planning to enter the building where the Jyllands-Posten daily has its Copenhagen news desk and "to kill as many of the people present as possible."

Scharf said the assault was to have been carried out sometime before this weekend, and could have been similar to the 2008 terrorist attack in Mumbai, India, that left 166 people dead.

"It is our assessment that the plan was to try to get access" to the newspaper office and "carry out a Mumbai-style attack," Scharf told reporters.

Danish Justice Minister Lars Barfoed said the plot was "terrifying" and "probably the most serious terror attempt in Denmark." Scharf, however, said there was no need to raise the nation's terror-threat alert level.

Danish intelligence said it arrested a 26-year-old Iraqi asylum-seeker living in Copenhagen and the three Swedish residents who had rented the car: a 44-year-old Tunisian, a 29-year-old Lebanese-born man and a 30-year-old whose national origin was not immediately released. The Danish resident was arrested in a separate raid, in a different Copenhagen suburb, from the other three, Scharf said.

Police evacuated a two-story apartment block where the Iraqi lived and were investigating an unidentified suspicious item found there, said PET and one resident, Birhe Kristensen.

The four men face preliminary charges of attempting to carry out an act of terrorism. A custody hearing was scheduled for today. Police in Denmark do not release the names of suspects.

The alleged plot follows several attacks and threats connected to 12 cartoons depicting the Prophet Muhammad published by the Jyllands-Posten in 2005 as a challenge to perceived self-censorship.