ISTANBUL — Saudi Arabia's public prosecutor announced Monday that five people have been sentenced to death in connection with the killing of journalist Jamal Khashoggi in the Saudi Consulate in Istanbul last year. But the two most senior officials implicated in the case, including an adviser to Crown Prince Mohammed bin Salman, were cleared of wrongdoing, the prosecutor said.

The slaying of Khashoggi in October 2018 sparked a global outcry against Saudi Arabia and led to greater scrutiny of a crackdown on dissidents pursued by the crown prince. Khashoggi, who contributed columns to The Washington Post, had been one of Mohammed’s most prominent critics.

Khashoggi was killed soon after he visited the Saudi Consulate to obtain documents that would allow him to remarry. After he was killed, by a team of agents who had flown to Istanbul from Saudi Arabia, Khashoggi’s body was dismembered, according to Turkish and Saudi prosecutors. His remains have not been found.

The verdicts came after a trial in Riyadh’s criminal court that lasted nearly a year and was largely shrouded in secrecy, with court sessions closed to the general public. Human rights groups warned that the lack of transparency made the proceedings unfair, and increased the likelihood that senior officials could escape justice.

Diplomats from the United States, Turkey and several other countries were allowed to attend but told not to reveal details of the trial. Members of Khashoggi’s family also attended, according to Shalaan al-Shalaan, a spokesman for the Saudi public prosecutor.

In addition to the five people who received the death penalty, three more people were sentenced to jail terms totaling 24 years, according to Shalaan, who did not name any of the convicted defendants. The death sentences must be confirmed by higher courts, he added.

The CIA concluded last year that the crown prince had ordered Khashoggi’ s assassination, contradicting Saudi Arabia’s insistence that Mohammed had no knowledge of the plot. However, Saudi authorities had said they were investigating the roles played by two senior aides to the crown prince in organizing and dispatching the team of agents who killed Khashoggi.

Shalaan said Monday that the two senior aides — Saud al-Qahtani and Ahmed al-Assiri — were exonerated.

Qahtani, a media adviser to the crown prince and one of the kingdom’s most strident defenders, was “investigated by the public prosecutor and was not charged because of lack of evidence against him,” Shalaan said.

Last year, the Trump administration imposed sanctions on 17 Saudi citizens, including Qahtani, saying he was “part of the planning and execution of the operation that led to the killing of Mr. Khashoggi.”

Assiri, Saudi Arabia’s former deputy head of intelligence, was initially charged after prosecutors said he was responsible for issuing the order for Khashoggi’s forcible return to Saudi Arabia. Shalaan said Monday that Assiri’s guilt “was not proved.”

Turkish officials insisted that Khashoggi’s killing was planned, even as Saudi Arabia maintained that the murder was a “rogue” operation carried out by overzealous agents who had been instructed to return Khashoggi to Saudi Arabia alive. On Monday, Shalaan said the investigation showed “there was no prior intention to kill at the start of this mission.”

The killing, he added, was a “snap decision.”

Saudi officials had repeatedly called Khashoggi’s killing a mistake and pointed to the trial as evidence that they were responding to international outrage. Human rights advocates said a fair trial was all but impossible in the kingdom, an absolute monarchy with no independent institutions and where the crown prince enjoys unrivaled power.

A report in June by a United Nations investigator called for a U.N.-assisted criminal inquiry, saying that Saudi authorities participated in the destruction of evidence after Khashoggi was killed and that culpability extended beyond the Saudis who are were on trial. The investigator, Agnès Callamard, said Khashoggi’s slaying “constituted an extrajudicial killing for which the State of the Kingdom of Saudi Arabia is responsible.”

Adam Coogle, a Middle East researcher for New York-based Human Rights Watch, said in text message Monday that Saudi Arabia’s “absolution of its senior leadership of any culpability in the murder of Jamal Khashoggi raises serious concerns over the fairness of the criminal proceedings.”

The kingdom’s handing of the killing — “from complete denial to hanging the murder on lower-level operatives in a trial that lacked transparency, demonstrates the need for an independent criminal inquiry,” he wrote.

Dadouch reported from Beirut.