OSLO — It was during breaks between marathon video game sessions in his mother’s apartment in Oslo that Anders Behring Breivik drafted his complicated and chilling plan.
He would kill indiscriminately with explosives and guns, surrender to authorities if he survived, then prove himself sane in court — all to publicize a manifesto accusing Muslims of destroying European society.
By any account, the attack went as he intended. A court ruled Friday that Breivik was sane when he killed 77 people, most of them teenagers, in attacks that shook Norway.
‘‘His goal was to be declared sane, so on that point he is satisfied,’’ said Breivik’s defense lawyer, Geir Lippestad.
The Oslo district court found the 33-year-old right-wing extremist guilty of terrorism and premeditated murder for the twin attacks on July 22 last year. Breivik first bombed government headquarters, killing eight people, before going on a shooting spree on Utoya island that left 69 dead at a summer camp for young members of the governing Labor Party.
Prosecutors had asked for an insanity ruling, which Breivik rejected as an attempt to deflate his radical anti-Muslim views. He smiled when the five-judge panel declared him sane and sentenced him to a 21-year prison sentence that can be extended for as long as he’s considered dangerous to society. Legal analysts say that likely means he will be locked up for life.
‘‘He has killed 77 people, most of them youth, who were shot without mercy, face to face. The cruelty is unparalleled in Norwegian history,’’ Judge Arne Lyng said. ‘‘This means that the defendant even after serving 21 years in prison would be a very dangerous man.’’
In his final words, Breivik regretted not killing more people, apologizing to other ‘‘militant nationalists’’ for not achieving an even higher death toll. He said he wouldn’t appeal the ruling because that would ‘‘legitimize’’ a court he said got its mandate from a political system that supports multiculturalism.
Prosecutors also said they would not appeal, bringing the legal process for Norway’s worst peacetime massacre to an end and providing closure for victims’ families and survivors, who have had to endure weeks of testimony from Breivik describing the victims as traitors for embracing immigration.
‘‘I am very relieved and happy about the outcome,’’ said Tore Sinding Bekkedal, who survived the Utoya shooting. ‘‘I believe he is mad, but it is political madness and not psychiatric madness. He is a pathetic and sad little person.’’
From Europe’s far right, the reaction was mixed. Some asserted that Friday’s verdict played into their core beliefs, though they have spoken out against his violent rampage.
‘‘It was obviously wrong what he did, but there was logic to all of it,’’ said Stephen Lennon, the 29-year-old leader of the English Defense League, an anti-Muslim group. ‘‘By saying that he was sane, it gives a certain credibility to what he had been saying. And that is, that Islam is a threat to Europe and to the world.’’
Frank Franz, a spokesman for the German far-right party NPD, distanced his party from Breivik. ‘‘We consider his deeds to be those of a murderer. It’s as simple as that,’’ Franz said. ‘‘For us, it had nothing to do with politics.’’
During the trial, Breivik said the massacre was meant to draw attention to a manual of far-right terrorism that he released on the Internet just before the attacks. In it, he predicted that the government would try to cast him as an ‘‘insane, inbred, pedophile Nazi loser’’ if brought before a court.
Breivik’s lawyers say he is planning to write new books from Oslo’s Ila Prison. He has access to a computer there but no Internet connection.
Since Breivik admitted to the attacks, his sanity was the key issue to be decided by the trial, with two psychiatric teams reaching opposite conclusions. One gave Breivik a diagnosis of paranoid schizophrenia, a severe mental illness that would preclude imprisonment. The other found him narcissistic and dissocial — having a complete disregard for others — but criminally sane.
The court criticized the assessment that found Breivik insane, saying his perception of being a commander in a civil war can be explained in the context of a ‘‘fanatic and right-wing extremist view of the world’’ rather than as delusions of a sick mind.
The son of a Norwegian diplomat and a nurse who divorced when he was a child, Breivik had been a law-abiding citizen until the attacks.
According to Breivik’s manifesto, he plotted for nearly nine years to carry out his attacks, but prosecutors said he only started planning after moving back with his mother in 2006.