Police in Copenhagen say they have shot dead a man they believe was behind two deadly attacks in the Danish capital hours earlier.
Police say they killed the man in the Norrebro district after he opened fire on them.
It came after one person was killed and three police officers injured at a free speech debate in a cafe on Saturday.
In the second attack, a Jewish man was killed and two police officers wounded near the city's main synagogue.
Police say video surveillance suggested the same man carried out both attacks. They do not believe any other people were involved.
The head of Danish intelligence said investigators were working on the theory that the gunman could have been inspired by the shootings in Paris last month. The attacks on the Charlie Hebdo magazine, a kosher supermarket and a policewoman claimed 17 lives.
Jens Madsen told reporters the man had been identified and had been on the agency's radar for some time.
Police were working to determine whether the man had travelled to Syria or Iraq, he said.
Prime Minister Helle Thorning-Schmidt said it was "a very sad morning" and described the shootings as "a cynical act of terror against Denmark".
"We do not know the motive for the alleged perpetrator's actions, but we know that there are forces that want to hurt Denmark. They want to rebuke our freedom of speech,'' she said, according to the Associated Press.
Ms Thorning-Schmidt later visited the synagogue and said Denmark would do everything to protect its Jewish community.
On Saturday a gunman attacked a free-speech debate hosted by controversial Swedish cartoonist Lars Vilks.
One man - identified by Danish media as film director Finn Norgaard, 55 - was killed and and three police officers wounded.
Officials said the gunman fled by car. A black Volkswagen Polo was found abandoned a short distance away.
Police said the gunman then called a taxi to take him home.
They used information from the taxi driver to identify the address, near the railway station in Norrebro. They released photos showing the alleged attacker wearing a purple balaclava and thick puffer jacket.
Hours later, a gunman opened fire outside a synagogue in Krystalgade street, about 5km from the scene of the first attack, killing a Jewish man and wounding two police officers.
The victim was named as Dan Uzan, 37. He had been on security duty while a bat mitzvah ceremony was taking place inside the synagogue.
Early on Sunday, police said they had been keeping the Norrebro address under observation, waiting for the occupant to return.
When the man appeared, he saw the officers, pulled out a gun and opened fire, police said. They returned fire and shot him dead.
At the scene: Malcolm Brabant, BBC News, Copenhagen
It was always a case of not if but when. What's surprising is that it has taken this long for Denmark to be scarred by a fatal terror attack.
In September it will be 10 years since the Jyllands Posten newspaper inflamed the Muslim world with the publication of 12 cartoons of the Prophet Muhammad, including one of him with a bomb in his turban.
The country has been perpetually vigilant since 2005, after its embassies in the Middle East were burned and Danish exports threatened.
Kurt Westergaard, the 79-year-old cartoonist who drew the seminal turban caricature, has spent the past decade living under a death fatwa (religious ruling). He narrowly escaped an attempt to kill him at home, and had to lock himself into a panic room when a Somali militant broke into his home in the city of Aarhus.
He continues to live under police protection.
French President Francois Hollande said Interior Minister Bernard Cazeneuve would visit the Danish capital on Sunday.
US National Security Council spokeswoman Bernadette Meehan said they had been in touch with their Danish counterparts and were ready to help with the investigation.
Israeli Prime Minister Benjamin Netanyahu called on Jewish people in Europe to migrate to Israel following attacks on Jews in recent weeks.
"This wave of attacks will continue. I say to the Jews of Europe - Israel is your home," he told a cabinet meeting.