CARACAS, Venezuela — For members of Venezuela’s opposition, the big question heading into Sunday’s elections seemed less about whether they would win than how much power they would be allowed to wield once they did.

Widespread dissatisfaction with President Nicolás Maduro’s ruling party was plain to see. Violent demonstrations had taken over the streets for months, while many thousands of Venezuelans had fled the country to escape scarcities of food and medicine, rampant violence and a triple-digit inflation. Polls had predicted that opposition candidates could nearly sweep the board in Sunday’s gubernatorial races, taking as many as 18 of the nation’s 23 statehouses.

Yet the result was the opposite: Candidates aligned with the president won at least 17 state races, some by wide margins. Opposition candidates took only five. They even lost in states that were considered overwhelmingly pro-opposition.

The results shocked the country and, according to Venezuelan and foreign analysts, raised new questions about the integrity of Venezuela’s electoral system.