Mexico’s Senate overwhelmingly passed a sweeping reform of the notoriously dysfunctional public school system early Wednesday, handing President Enrique Pena Nieto an important victory in his push to remake some of his country’s worst-run institutions.

The Senate voted 102-22 in favor of a standardized system of test-based hiring and promotion that would give the government the tools to break teachers unions’ near-total control of school staffing.

That control includes the corrupt sale and inheritance of teaching jobs, and it has been widely blamed for much of the poor performance of Mexican schools, which have higher relative costs and worse results than any other in the 34-nation Organization for Economic Cooperation and Development.

“The inheritance and sale of jobs has ended,” Education Secretary Emilio Chuayffet said on Twitter. “Merit is the ideal means of access to, and progress in, a teaching career.”

Among the benefits ended by the educational reform are payments of more than $100 million a year by some estimates to thousands of teachers who work full-time as union organizers and rarely, if ever, set foot inside a classroom. Education reform groups have found some union representatives earning hundreds of thousands of dollars per semester.

The vote clears a path for Pena Nieto to move forward with a series of even more controversial reforms, including a measure that would test one of modern Mexico’s longest-standing taboos by allowing private investment in the state-run oil company.

But there could be trouble ahead.

Education advocates say a series of concessions to the smaller of the two main teachers unions undermined the reform’s ability to create true change in the national education system.

And despite those concessions, the smaller teachers union continued days of debilitating demonstrations in Mexico City, sending tens of thousands of supporters to shut down the capital’s main boulevard and protest outside key government buildings Wednesday.

The education reform initially pitted Pena Nieto against the country’s main teachers union — Latin America’s largest union and once one of the most important allies of his Institutional Revolutionary Party. The union, known by the Spanish acronym SNTE, fell into line after its head, Elba Esther Gordillo, was arrested on corruption charges in February. She remains jailed pending trial.

A smaller, dissident union known as the National Education Workers’ Coordinating Committee, or CNTE, continued protesting and eventually rallied thousands of teachers from poor southern states, paralyzing large sections of the capital for more than a week.

Much of Mexico’s educational dysfunction is attributed to the relationship formed more than a half-century ago between the Institutional Revolutionary Party and the teachers unions, which gained increasing control of the education system in exchange for throwing their strength behind the government in the voting box and on the streets.

Over the years the unions developed a virtual lock on teacher hiring and promotion. Almost every new teacher must go through a union to gain a school assignment, a practice that has spawned notorious levels of corruption, including the sale and inheritance of teaching positions.

Particularly in states with schools controlled by the CNTE, critics say, union influence has transformed schools from educational institutions into mechanisms for extracting funds from the state. The CNTE has become notorious for threatening elected officials with debilitating strikes and marches in order to maintain and increase benefits that make teaching one of the primary sources of legal income in much of rural Mexico.