Police arrested a suspect, a 42-year-old Norwegian man of Iranian descent, shortly after the shooting started around 1:00 am (2300 GMT Friday) in three locations in central Oslo.
"The police are investigating the events as a terrorist attack," police said in a statement.
Organisers of the Pride march that was due to take place on Saturday afternoon said they were calling it off.
"All events linked to Oslo Pride have been cancelled" following "clear" recommendations by police, the organisers wrote on Facebook.
Police said two people had died and 21 were wounded, including 10 seriously, and said two weapons had been seized.
The man arrested "is suspected of homicide, attempted homicide and a terrorist act", senior police official Christian Hatlo told a press conference.
The terror charge comes because "of the number of wounded and killed, the number of crime scenes... and there is good reason to believe that he had intended to sow terror", Hatlo said.
Police received the first reports at 1:14 am and the suspect was arrested five minutes later, police said.
Police said they were able to quickly apprehend the suspect thanks to the "heroic contribution" of bystanders.
Norway's anti-terrorist service said on Twitter that it was looking into whether other attacks could be possible but that for the moment "we have no indication of this."