SAO PAULO — Brazil's highest court voted Thursday to restrict a legal protection afforded federal lawmakers that critics say has resulted in impunity, as the country grapples with massive official corruption.

The protection known as "privileged standing" allows tens of thousands of politicians to have cases against them tried in higher courts than a normal citizen would. It can result in cases against politicians moving very slowly because they frequently shift venues as defendants switch jobs.

But the problem is particularly acute for federal lawmakers, whose cases are tried by Brazil's top court. The Supreme Federal Tribunal's docket is so overloaded that critics say politicians tried there rarely face the consequences of their crimes.

The top court decided Thursday that the privileged standing should only apply to crimes allegedly committed while the lawmaker is in office and that are related to the exercise of that office. That should greatly reduce the number of cases against lawmakers that stall at the top court.

Seven of the court's 11 justices voted for the restriction, while the other four voted for a narrower one. The court also set a deadline — the moment when the charges are formalized — after which cases would no longer change venue. That should also reduce the amount of time it takes a case to reach a conclusion.

Justice Luis Roberto Barroso strongly advocated for the restrictions, calling privileged standing a "disaster" for Brazil. But Justice Gilmar Mendes warned that the limitation would not be a panacea for what ails Brazil's justice system, using his vote to make a laundry list of everything from poorly managed prisons to excessive vacation time for judges.

Still, experts say the limitations could result in much swifter justice for senators and deputies.

It should also be a major boost to Brazil's watershed Operation Car Wash probe, in which prosecutors have alleged that Brazil's government was effectively run like a cartel for years, with politicians doling out favors and state contracts in exchange for bribes and campaign contributions. The investigation has shaken Brazil's political system and put dozens of powerful people in jail.

But while the probe has made great strides, most of its most prominent convictions have been against executives. The big-name politicians it has netted — like former President Luiz Inacio Lula da Silva and former Speaker of the House Eduardo Cunha — were convicted after they lost privileged standing, and their cases were tried in regular courts.

In the four years since the probe began, the Supreme Federal Tribunal has yet to hand down a single verdict in a Car Wash case.