Sudan’s military and civilian leaders signed a landmark power-sharing deal at a joyous ceremony in the capital, Khartoum, on Saturday, signaling a new chapter in the life of the sprawling African country, which has been rocked by eight months of popular protests, a coup and a bloody military crackdown.

Few Sudanese could have imagined only a year ago that Omar Hassan al-Bashir, their despised ruler of 30 years, would be languishing in Sudan’s most notorious prison awaiting a trial on corruption charges that is expected to start on Monday. Street celebrations, with music, poetry and fireworks, were held across the country Saturday.

In a region where numerous revolutions have failed or horribly backfired in recent years, the Sudanese hope to be an exception.

But for many, the euphoria was tempered by the painful realities of the country’s economic collapse, and the tough compromises of a power-sharing deal that ensures the military, led by some of Mr. al-Bashir’s closest deputies, will retain its grip on power.