During the campaign, Ms. Gómez and the other opposition candidates repeatedly sought to cast the election as a referendum as much on the P.R.I.’s leadership as on the party’s regional governance.

They urged voters to break the P.R.I.’s dynastic control as the only solution for ridding the state — and by extension, the nation — of its chronic corruption and impunity, and finally curbing the violence. Mr. del Mazo is a scion of P.R.I. royalty: His father and grandfather were governors of the state, and Mr. Peña Nieto, who previously served as the state’s governor, is his cousin.

“Today there is hope. I think there really is a chance, because people are fed up,” said Salvador Albino, 47, a chauffeur for an affluent family who was on his way to vote in the municipality of Naucalpan on Sunday. “We need something different. We need something new.”

But optimism among opposition supporters was severely tempered by the hard experience of having lived through so many decades of P.R.I. dominance, cemented by the party’s formidable campaign machinery and its ability to muster votes through patronage jobs, handouts and other techniques.

“I think the people want another party,” said Juan Hernández, 48, an airport employee, who was sitting in a square in the town of Ocoyoacac on Sunday after voting for one of the opposition candidates. “But the P.R.I. has all the power and the money and is putting all that money in the campaign.”