Police said the unnamed man who killed two people at a cultural centre and a synagogue was known to police and may have been inspired by the Paris Islamist attacks last month that claimed the lives of 17 people.
At the synagogue in the centre of Copenhagen, tearful Danes laid flowers and lit candles in memory of the victims of the worst such attack in the history of the small Scandinavian nation.
Danish broadcaster TV2 identified the assailant as a 22-year-old who was born and raised in Denmark and who was known to police because of his involvement in gangs.
In a killing spree that bore a striking resemblance to the Paris attacks, the gunman first fired off a volley of bullets at a cultural centre where a panel discussion about Islam and free speech was taking place last evening.
More From This Section
A 55-year-old man identified by the media as documentary film maker Finn Norgaard was killed at the event, which was also attended by Lars Vilks, a Swedish cartoonist behind a controversial caricature of the Prophet Mohammed, and the French ambassador.
Five police officers were also wounded in the two attacks that stoked fear in the city of about one million people.
Police tracked the suspect down to a building in the working class neighbourhood of Norrebro, killing him after an exchange of fire.
Police said he was already "on the radar" of the intelligence services and that they were looking into the possibility he had travelled to conflict zones such as Syria and Iraq.
He said the man may "generally have been inspired by militant Islamist propaganda issued by IS (Islamic State) and other terror organisations".
A photo was released of the suspect in the cultural centre attack, wearing a black puffer jacket and a maroon balaclava and carrying a black bag.
Police said they believe he had acted alone, but armed officers raided a Copenhagen Internet cafe in one of a series of operations on Sunday, leading away at least two people, possibly under arrest, local media said.