Anders Behring Breivik, the right-wing extremist who killed 77 people in Norway last July, was declared sane and sentenced to 21 years in prison by a Norwegian district court Friday.

The panel of five judges, led by Wenche Elizabeth Arntzen, was unanimous in their decision.

Breivik has been found sane and sentenced to 21 years in prison, with 445 days deducted for his time in custody, the Daily Telegraph newspaper of Britain reported.

Breivik received the maximum sentence allowed under Norwegian law.

However, it is likely that Breivik may never be freed, since the court can keep prolonging his sentence if he is regarded as a danger to society. Judge Arntzen described the sentence as preventive detention, which is reserved for extremely dangerous convicts.

Breivik, who appeared confident and smiling before the judgment, made a wry smile when the sentence was delivered.

He will serve his term in Oslo’s Ila prison, a high-security facility where he has been held in isolation since his arrest last summer.

The prosecution had asked the court to declare Breivik insane and sentence him to a psychiatric asylum. They can still appeal the judgment.

The defense argued that Breivik should be declared sane since he believed the killings were “justified.” Breivik claimed himself to be a warrior fighting to save Norway from Islamization.

Indeed, Breivik pleaded not guilty on the grounds that he believed his acts were based on goodness, not evil and were cruel but necessary to defend Norway against a growing Muslim presence. However, he freely admitted to the murders, as well as wounding about 240 other people during his killing spree.

During the trial, he confessed to setting off a car bomb that killed eight people outside a government building in Oslo and killing 69 others on the island of Utoya. Most of the dead were teenagers attending a Labor Party youth camp.

The judgment will put the right wing extremist in jail -- a situation that he described as pathetic. However, he will be able to continue making statements against immigration and multiculturalism from jail. Earlier, he said that he may write a book on the issue to continue his fight.