Brazil's top court on Tuesday spared leading presidential candidate Jair Bolsonaro from having to stand trial for racism, less than a week after the far-right politician was injured in a knife attack during a campaign event.

A court panel voted 3-2 to drop a racism accusation against Bolsonaro, who leads polls ahead of October's election after Brazil's Workers' Party decided that it would not field imprisoned former President Luiz Inacio Lula da Silva as its candidate.

Justice Alexandre de Moraes ruled that Bolsonaro had the right to voice disrespectful opinions toward blacks in a 2017 speech at a club in Rio de Janeiro. He also pointed out that Bolsonaro has immunity as a sitting lawmaker.

Bolsonaro said last year that members of rural settlements founded by the descendants of slaves, called "quilombolas," are "not good even to procreate." He also talked about the weight of those slave descendants using a measure that Brazilian farmers apply to animals.

Moraes said those comments did not exceed the limits of his freedom of expression.

Bolsonaro will still have to stand trial for accusations of slander and incitation to rape. Both are related to an incident at Brazil's lower house in 2014, in which he said he would not rape left-leaning congresswoman Maria do Rosario because she was not his type and "did not deserve it."

The Sao Paulo hospital where Bolsonaro is being treated for the knife wound to his abdomen said Tuesday that he is no longer in intensive care and is instead in a semi-intense care unit.

A tape obtained by TV Globo showed Bolsonaro's alleged attacker, Adelio Bispo de Oliveira, giving his first testimony in court after Thursday's attack in Juiz de Fora, a city north of Rio de Janeiro.

De Oliveira calmly says he only wanted to give Bolsonaro a scare and acted alone because of political and religious motivations.

"I feel threatened, like millions of people, by the speeches this citizen has made," de Oliveira said.

He also admitted he stopped taking his medication. His lawyers argue he is not mentally fit to stand trial.

A Datafolha poll published on Monday shows Bolsonaro leading with 24 percent support, ahead of left-leaning Ciro Gomes at 13 percent support, centrist Marina Silva with 11 percent and right-leaning Geraldo Alckmin with 10 percent.

Former Sao Paulo Mayor Fernando Haddad, who the Workers' Party announced as da Silva's replacement on Tuesday, had 9 percent.

If no candidate gets more than 50 percent of the votes on Oct. 7, a runoff will be held on Oct. 28.

The Datafolha poll had a margin of error of 2 percentage points. All the 2,804 voters sampled were interviewed on Monday.