The sentence was welcomed by the widow of the American soldier Khadr killed as a 15 year old, when he threw a grenade at the end of a firefight in Afghanistan in July 2002.
"Today is a huge victory for my family . . . and for hundreds of families out there," said Tabitha Speer, who earlier in the week blasted Khadr as a killer.
"The plea, for us, is final."
The pre-trial deal also calls for Khadr, 24, to serve one more year in U.S. custody. After that, he can apply to transfer to Canada to serve out the balance of his sentence under Canadian terms. That suggests he would be eligible for parole soon after he returns to the country of his birth.
Diplomatic notes between Washington and Ottawa released Sunday show the U.S. will support the transfer, and Canada will look on it "favourably."
Despite the "dip notes," a spokeswoman for Foreign Affairs Minister Lawrence Cannon would not speculate on whether Canada would agree to the request.
"He would be treated like any other Canadian who applies for a transfer," Melissa Lantsman said in an email.
"The decision on any potential transfer will be made in accordance with current law. No decision can be made until an application is received."
The Pentagon issued its own statement, saying Canada and the U.S. had exchanged notes reflecting that "both would support Khadr's transfer to Canadian custody" after one more year.
The prosecution said the jury's desired sentence sent a message both to Khadr and to terrorists around the world, but defended the plea deal as the best way to bring a definitive end to the case.
"What this represents to the government is the certainty of a conviction, it represents the end of a case that spans five years," said Capt. John Murphy, chief of prosecution for the military commissions.
"It ends all appeals. This case is over."
Murphy said the prosecution had an obligation to put "all of the most serious, aggravating facts" before the jury, which was not told about the sentence cap agreed to beforehand.
The secrecy was aimed at not prejudicing their decision, which could have resulted in a lower sentence than the eight years.
Had they imposed a term of less than eight years, it would have applied.
Among other things, Khadr waived his rights to appeal or to take action against the U.S. as part of the agreement.
The Toronto-born Khadr pleaded guilty last Monday to five war crimes, including to the murder of Sgt. 1st Class Chris Speer and other terrorist-related charges.
Under an agreed statement of facts, he admitted to being an al-Qaida terrorist who wanted to kill as many Americans as possible.
His Canadian defence lawyer Dennis Edney denounced the process that saw the first juvenile prosecuted for war crimes in six decades.
"The fact that the trial of a child soldier, Omar Khadr, has ended with a guilty plea in exchange for his eventual release to Canada does not change the fact that fundamental principles of law and due process were long since abandoned in Omar’s case," Edney said.
"In exchange for repatriation, Omar was required to sign an admission of facts which was stunning in its false portrayal of him."
After more than eight hours of deliberations over two days, the seven military officers called for the hefty punishment. They declined to discuss their sentencing decision with the media.
Their call for 40 years behind bars was much stiffer than what the prosecution had wanted, while the defence had requested him sent back to Canada immediately.
Khadr was expected to be transferred in short order to Camp 5, Guantanamo Bay's maximum security prison, where he would be kept essentially in segregation. He has been in Camp 4, where inmates live communally and have a degree of freedom.
The chief of defence for the military commissions, Col. Jeffrey Colwell, expressed disappointment in the severity of the sentence.
At the same time, the plea deal has to be seen as a victory, given that Khadr can return to Canada within a year.
"That in and of itself is a remarkable feat," Colwell said.
"He'll get back to Canada, back to his home, where he belongs, period."
Human-rights observers denounced the entire process and its outcome. They noted the military commission system has been condemned within the United States and around the world as illegitimate.
They have been especially outraged that the U.S. would try a 15 year old for war crimes.
Andrea Prassow, with Human Rights Watch, said the commission system cannot produce a fair result.
"The system is flawed. The system is broken and it can't be fixed," she said.
Alex Neve, of Amnesty International Canada, called Khadr's ordeal a "fiasco."
"That a jury would think that a 15-year-old child soldier . . . who has credibly alleged being tortured, threatened and coerced in U.S. custody is deserving of a 40 year prison sentence is staggering," Neve said.
After they announced their sentence, presiding judge Col. Patrick Parrish thanked the officers, dismissed them, and imposed the eight-year sentence agreed to before trial.
Before announcing its decision, the panel asked the judge to replay the testimony of a defence witness who spoke of Khadr's "rehabilitative" potential.
The panel deliberated longer than any other military-commission sentencing jury.
Under the rules, at least six of the seven jurors had to agree on the punishment they wanted.
The prosecution on Saturday called for at least 25 years on top of the eight Khadr has spent in custody.
"Make no mistake. The world is watching," prosecutor Jeff Groharing told the panel Saturday morning.
"Your sentence will send a message."
However, the defence stressed Khadr's age when he committed his crimes, saying he was the victim of a "bad daddy."
Khadr's father, Ahmed Said Khadr, who was killed by Pakistani forces, was a purported ranking member of al-Qaida and a close associate of terrorist mastermind, Osama bin Laden.
Former Sgt. Layne Morris, who was partially blinded in the firefight in which Speer was killed, denounced the plea deal, noting that Canadian politicians once intervened to have the elder Khadr released from Pakistani custody.
He called it an "outrage" Khadr was on a fast-track to freedom as a result of political meddling.
"I would urge the Canadian government to think carefully about what to do with this young man when the time comes," Morris said.
"And to take all precautions to ensure that Mr. Khadr and the Khadr family are no longer threats to our way of life."
More than 1,000 American service members have been killed in Afghanistan but Khadr is the only captive the U.S. has charged with murder in connection with a death.
Khadr himself gave a statement to the sentencing hearing, saying he was "really, really sorry" for the pain he had caused Speer's wife and children. He said his greatest wish was to get out of Guantanamo Bay.
Speer insisted she found Khadr's apology hollow.
"The only regret he has is that he has been here for eight years — he got caught, and he feels bad for that," Speer said.
"He will forever be a murderer in my eyes."