A court in Saudi Arabia sentenced five people to death Monday for "committing and directly participating" in the murderof Washington Post journalist Jamal Khashoggi in the Saudi consulate in Istanbul last year.

Three others were sentenced to a collective total of 24 years in prison for their "role in covering up" the killing, Saudi Arabia’s public prosecutor said in a statement posted by the Foreign Ministry on Twitter.

"May his soul rest in peace," the statement added.

The investigation concluded that the murder was not premeditated and that the perpetrators agreed to kill the journalist when they found it would be too hard to move him to another location, the deputy public prosecutor, Shaalan al-Shaalan, said in a press conference carried by state television.

Al-Shaalan said the investigation determined that "there was no prior intention to kill him at the beginning of the mission and the death happened on the spot."

He said that the crown prince's former top adviser, Saud al-Qahtani, was questioned, tried but not convicted. Ahmed Asiri, the former deputy head of Saudi intelligence, was released due to a lack of evidence. Al-Qahtani was sanctioned by the United States last year.

The court was withholding names of the accused until all appeals were exhausted.

Al-Shaalan added Monday that Khashoggi's sons were allowed to attend. Representatives from the embassies of the five members of the United Nations Security Council and Saudi human rights representatives also attended, he added. NBC News could not independently verify these claims.

The trials were carried out in near total secrecy, but in response to a question Monday about why the media was unable to attend, Al-Shaalan said press coverage had been permitted. He did not offer any explanation for the discrepancy in the account.

Khashoggi, a U.S. permanent resident and a vocal critic of the crown prince, was murdered and dismembered on Oct. 2, 2018, in the Saudi consulate in Istanbul.

His killing and the botched Saudi response triggered a wave of revulsion and anger around the world that appeared to catch the kingdom's officials by surprise.

Prosecutors investigated 31 people in relation to the murder of Khashoggi, 21 of whom were arrested, the statement from the public prosecutor said. Eleven of the 21 were charged and tried in court, five of whom were sentenced to death Monday, three were handed a prison sentence and three others were found not guilty, the prosecutor added.

In response to the sentencing decision, a senior Trump administration official told NBC News it is "an important step in holding those responsible for this terrible crime accountable, and we encourage Saudi Arabia to continue with a fair and transparent judicial process."

In the wake of the murder last year, Saudi officials said 15 men were sent by its intelligence services to Istanbul to persuade Khashoggi to return to his home country, but ended up killing him when he resisted. But a report by the U.N. extrajudicial executions investigator, Agnes Callamard, in June identified the men and found that six of them had not been indicted in Saudi Arabia. It was unclear how many of the 15-man team were among those sentenced Monday.

Callamard's report concluded that there was "credible evidence" that high-level Saudi officials, including the powerful crown prince, could be liable for Khashoggi’s killing. She called on U.N. Secretary-General Antonio Guterres to "demand" a follow-up criminal investigation.

Saudi Arabia has repeatedly said Khashoggi's death was a domestic issue.

Nevertheless, Callamard on Monday tweeted that "the travesty of investigation, prosecution and justice continues."

And Adam Coogle, a Middle East researcher for Human Rights Watch, tweeted that "Saudi Arabia has cleared all senior officials in the Khashoggi murder."

"This was telegraphed in Nov 2018 when prosecutors alleged that the team on the ground murdered Khashoggi against orders to merely kidnap him (apparently the kidnap plot itself was not a problem for the court)," he added.

The CIA has concluded that Crown Prince Mohammed ordered Khashoggi’s killing. The claim has been resolutely rejected by Riyadh.

President Donald Trump condemned the killing, and the U.S. sanctioned 17 Saudis suspected of being involved, though not the crown prince. But the Trump administration has faced criticism for its defense of the U.S.-Saudi relationship. The absolute monarchy is a longtime U.S. ally, but under Trump, King Salman and his son, the crown prince, have become linchpins of American policy in the region.