CARACAS, Venezuela — Government opponents surged to a rare victory here on Sunday in key congressional elections framed by the country’s deep economic crisis, claiming a legislative majority for the first time in years and handing a significant setback to the heirs of former President Hugo Chávez and his socialist-inspired movement.

The victory significantly alters the political balance in this deeply divided country and augurs a power struggle between the long-marginalized opposition and the government of President Nicolás Maduro, the successor and disciple of Mr. Chávez.

Tibisay Lucena, the head of the electoral commission, announced about 12:30 a.m. Monday that the opposition, represented by the Democratic Unity coalition, had won 99 seats and that the government’s United Socialist Party had won 46 seats. She said final results were not in for 22 seats.

“Change has started today in Venezuela,” said Jesús Torrealba, the head of the Democratic Unity coalition.