ISLAMABAD, Pakistan — Pakistan’s fragile democracy reached a milestone on Saturday when the government stepped down at the end of its five-year term, setting the stage for elections due to take place by mid-May.

The action was a first in a country where the powerful military has regularly ousted civilian governments, either directly through coups or indirectly through constitutional maneuvers, and it offered hope that the parliamentary system was maturing.

Still, a faltering economy and widespread militant violence have left many Pakistanis grumbling about the lack of tangible dividends from democracy, and the governing Pakistan Peoples Party, whose performance has been widely criticized, will face a strong challenge from the opposition leader, the former Prime Minister Nawaz Sharif.

In a televised address to the nation that was heavily steeped in his party’s history, Prime Minister Raja Pervez Ashraf defended his government’s record. Talks with the opposition over the formation of a caretaker administration, which would run the country until the elections, were continuing, he said.