A 42-year-old man has been arrested and charged with murder, attempted murder and terrorist acts after a shooting in the centre of Norway's capital, Oslo.
Two people died and 21 were wounded early on Saturday in what police called an "act of Islamist terrorism".
The shootings were in and near the London Pub, a popular LGBTQ+ venue, the Herr Nilsen jazz club and another pub.
Norway's prime minister told the BBC the suspect was questioned in May, but was not deemed a threat at the time.
"We now need to see the result of an investigation," PM Jonas Gahr Stoere told the BBC's Newshour programme late on Saturday.
The shooting started at about 01:15 local time on Saturday (23:15 GMT Friday), officials said.
Eyewitnesses said the suspect took out a gun from his bag and started firing, forcing terrified people to either throw themselves to the ground or flee.
The attacker was arrested by police officers - who were helped by bystanders - minutes later. Two weapons were retrieved at the crime scene by police, one of them a fully automatic gun.
The authorities later said the suspect was a Norwegian national.
Of the 21 injured, 10 were in a serious condition.
The terror alert level in Norway has now been raised to its highest level, though the country's PST intelligence service said it currently had "no indication" further attacks were likely.
Oslo's annual gay Pride parade was due to be held on Saturday, and was formally cancelled on police advice.
But despite that, hundreds of people marched near the scene later in the day, shouting: "We're here, we're queer, we won't disappear!"
"I think it's fantastic that this march is taking place, otherwise he would have won," one woman in her 50s told AFP news agency.
Rainbow flags and flowers were laid near the scene of the attack, which was sealed off by police tape, and bystanders comforted each other with hugs.
The gunman was known to security services since 2015 as a "suspected radicalised Islamist", and had a history of mental illness, Norway's PST intelligence service said.
"There is reason to think that this may be a hate crime," police said earlier. "We are investigating whether... Pride was a target in itself or whether there are other motives."
King Harald, Norway's monarch, said he and his family were "horrified" by the violence. He said "we must stand together" to defend "freedom, diversity and respect for each other".
EU Commission President Ursula von der Leyen tweeted that she was "shocked by the heinous attack on innocent people", while French President Emmanuel Macron said: "We stand stronger against hate if we stand together."
In the US, John Kirby, a spokesman for the White House's National Security Council, said: "We're all horrified by the mass shooting in Oslo today targeting the LGBTQI+ community there and our hearts obviously go out to the all the families of the victims, the people of Norway, which is a tremendous ally, and of course the LGBTQI+ community there and around the world,"
Witnesses who were at the London Pub have told how they fled to the basement, where 80 to 100 terrified partygoers were trying to hide.
Bili Blum-Jansen told TV2: "Many called their partners and family, it felt almost as if they were saying goodbye. Others helped calm down those who were extremely terrified."
Another survivor told how he was hit by flying glass.
"I just noticed that a shot was fired, and I was hit by a shard of glass. There were more and more and more shots, so I escaped into the inner bar and tried to get as many as possible with me," he told Norway's public broadcaster NRK.
"I saw a man arrive with a bag, he picked up a gun and started to shoot," said journalist Olav Roenneberg of public broadcaster NRK, who was in the area at the time.
A woman told the Verdens Gang newspaper that the gunman had taken careful aim at his targets. "When I understood that it was serious, I ran. There was a man covered in blood motionless on the floor," she said.
Another man told the newspaper he had seen a lot of people on the ground with head wounds.