Authorities said the suspect, a 42-year-old Norwegian citizen of Iranian origin, was believed to be a radicalised Islamist with a history of mental illness who had been known to intelligence services since 2015.
The suspect will be subjected to a psychiatric evaluation in the coming days as part of the investigation, police said.
The attack took place in the early hours of Saturday, with victims shot inside and outside the London Pub, a long-standing hub of Oslo's LGBTQ scene, as well as in the surrounding streets and at one other bar in the centre of the Norwegian capital.
The deceased were two men in their 50s and 60s, police said.
"Everything indicates that this has been an attack by an Islamist extremist," Prime Minister Jonas Gahr Stoere told a news conference.
"We don't (yet) know if the queer community was the intended target, but we know it is a victim."
Bili Blum-Jansen, who was in the London Pub, said he fled to the basement to escape the hail of bullets and hid there along with 80 to 100 other people.
"Many called their partners and family, it felt almost as if they were saying good-bye. Others helped calm down those who were extremely terrified," he told TV2.
"I had a bit of panic and thought that if the shooter or shooters were to arrive, we'd all be dead. There was no way out."
Rainbow flags symbolising the Pride community were on prominent display across Oslo this week, but Saturday's planned parade was cancelled on the advice of police.
"Last night the rainbow was coloured black," said Anette Trettebergstuen, Norway's minister of culture and equality and herself a prominent campaigner for LGBTQ rights.