The BBC's Malcolm Brabant says police tracked the gunman down using CCTV
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.
"We assume that it's the same culprit behind both incidents, and we also assume that the culprit that was shot by the police task force... is the person behind both of these assassinations," Chief Police Inspector Torben Molgaard Jensen told a news conference.
He said police would maintain a high presence in the city.
Prime Minister Helle Thorning-Schmidt said it was "a very sad morning" and described the shootings as "a cynical act of terror against Denmark".
"I am happy and relieved that police have disarmed the alleged perpetrator behind the two shootings," she said in a statement. "I will continue to encourage everyone to follow police instructions and be vigilant."
Early on Sunday, police said they had been keeping an address under observation in the district of Norrebro, waiting for the occupant to return.
When he appeared, he noticed the officers, pulled out a gun and opened fire, police said. They returned fire and shot him dead. The incident happened near Norrebro train station.
Police quickly sealed off the scene where the suspected gunman was shot in Norrebro
The shooting near the synagogue was the second in Copenhagen in a matter of hours
Norrebro is about three miles (5km) from the synagogue where the shooting took place just hours earlier.
A massive manhunt was launched after the first shooting, which took place during a free speech debate at the Krudttonden cultural centre hosted by controversial Swedish cartoonist Lars Vilks.
An audio recording, obtained exclusively by the BBC, revealed the moments leading up to the attack. One of the speakers at the debate is suddenly interrupted by a barrage of gunshots.
An audio recording captured the moment the gunman struck in the first attack (listeners may find content distressing)
A 55-year-old man attending the event was killed and three police officers wounded.
Witness Dennis Myhoff-Brink told the BBC: "People were trying to get to the doors, trying to get out of the room, hiding between or behind the tables and chairs, and some people were running out into the street."
Officials said the gunman fled by car, and a black Volkswagen Polo was later found abandoned a short distance from the scene.
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.
Police released photographs 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.
A Jewish man was fatally shot in the head and two police officers suffered injuries to their arms and legs. The attacker fled.
A Jewish community group later said that the man killed had been on security duty while a Bar Mitzvah ceremony was taking place inside the synagogue.
World leaders condemned the attacks.
French President Francois Hollande said Interior Minister Bernard Cazeneuve would visit the Danish capital on Sunday.
UK Prime Minister David Cameron said his thoughts were with the Danish people.
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.
Police warned the public to avoid central Copenhagen as they investigated the shootings
Copenhagen was on high alert as the manhunt continued
Police released this picture of the alleged gunman in the first shooting
Cartoonist Lars Vilks, who has faced death threats over his caricatures of the Prophet Muhammad, said he believed he was the intended target of the first attack. He was unhurt.
The French ambassador, Francois Zimeray, was also present during the attack.
A description of the debate at the cafe asked whether artists could "dare" to be blasphemous in the wake of attacks by Islamist gunmen in Paris last month against satirical magazine Charlie Hebdo.
In the French attacks, two gunmen opened fire at Charlie Hebdo's office, shooting dead 12 people. The next day a suspected accomplice of the militants shot dead a policewoman and later took hostages at a Jewish shop, killing four of them.
All three attackers were eventually shot dead by police and security services.