ALGIERS, Algeria — Two former prime ministers of Algeria accused of corruption were convicted and sentenced to prison on Tuesday in a landmark trial, unleashing cheers of joy from pro-democracy activists demanding an overhaul of the gas-rich country’s political system.

The verdict came amid high political tensions, with Algeria to vote on Thursday in a disputed presidential election to replace President Abdelaziz Bouteflika, who was pushed out of office in April after 20 years in power.

Protesters gathered outside and inside the courthouse in Algiers to hear the verdicts against the two former prime ministers, Ahmed Ouyahia and Abdelmalek Sellal. Some shouted, “Gang of gangsters!” and many waved or wore Algerian flags. The police surrounded the courthouse.

Mr. Ouyahia was sentenced to 15 years in prison and $16,000 in fines. Mr. Sellal was sentenced to 12 years in prison and $8,000 in fines. The men, who deny wrongdoing, have 10 days to appeal.