COPENHAGEN, Denmark – Police in Denmark and Sweden said they thwarted a terrorist attack possibly hours before it was to begin Wednesday, 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 Security and 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 service. He 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 Tuesday or Wednesday.

“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 has its Copenhagen office 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 said there was no need to raise the nation’s terror threat alert level.