Peru’s supreme court on Thursday sentenced the former leftwing president Pedro Castillo to 11 years, five months and 15 days in prison for trying to disband Congress and rule by decree in December 2022.

Labelled Peru’s first poor president, the former rural schoolteacher, who had never held elected office before winning the presidency, was impeached by Congress and jailed on the same day after his attempted power grab.

He had repeatedly clashed with an opposition-dominated Congress during his 16 months in power.

The verdict in his case comes a day after another leftwing ex-president, Martín Vizcarra, was sentenced to 14 years’ imprisonment for bribe-taking while serving as a regional governor.

Vizcarra joined two other former presidents already behind bars at a special penitentiary for ex-leaders in Lima: Ollanta Humala (2011-2016) and Alejandro Toledo (2001-2006). Castillo, 56, was also imprisoned at the facility pending his trial.

Castillo, a former trade unionist who won power in 2021 on a promise to uplift Peru’s poor, took the shock decision to dissolve Congress to try to avoid impeachment for alleged corruption. His stunt failed spectacularly, however, with members of his own government siding against him.

He was arrested while on his way to the Mexican embassy with his family to seek asylum. He was charged with rebellion, abuse of power and disturbing public order, but was acquitted on Thursday of the two latter charges.

Prosecutors had sought a 34-year prison sentence.

His eight-month trial took a dramatic turn earlier this month when his former prime minister, Betssy Chávez, also put in the dock, was given asylum by the Mexican embassy.

Peru broke off diplomatic ties with Mexico over what it called an “unfriendly act” and has not ruled out storming the Mexican embassy to arrest her.

Castillo’s arrest and impeachment sparked mass protests in 2022 among his working-class rural base. The protests were harshly repressed, leading to at least 50 deaths.

His deeply unpopular successor, the former vice-president Dina Boluarte, led the country for a tumultuous 22 months marked by a deep security crisis before also being impeached in October.