A majority of the 11-member Supreme Federal Court voted to find it unconstitutional to exclude sexual orientation and gender from Brazil’s anti-discrimination law.
After the sixth member voted in favour of the ruling, securing the majority, the court suspended the hearing until 5 June.
The remaining members are expected to vote then, and the ruling would be issued.
It would establish a way for people who experienced discrimination or physical attacks based on their sexual identity or gender orientation to sue.
Mr Bolsonaro, a social conservative, has said that if one of his sons were gay, he’d rather he be dead.
Last month, he discouraged gay tourists from visiting the country, and told journalists that Brazil cannot become known as a “gay paradise”.
Brazil led the world in transgender homicides with 171 in 2017, the last year for which statistics are available, according to the organisation TransEurope. Someone is killed in a homophobic attack here every 16 hours.
As Mr Bolsonaro campaigned last year, reports of crimes against LGBT+ people tripled.
After he took office in January, Brazil’s only openly gay congressman gave up his seat and fled the country amid death threats.
“It is a decisive win for the LGBT community,” said Flavio Grossi, a criminal defence lawyer who represents LGBT+ clients.
“LGBT people are scared. I have seen an increase in clients reporting instances of physical aggression, hate crimes and racism.”
Brazil’s LGBT+ community has secured major victories through the supreme court, including the right to marry in 2013 and to legally change names and genders in 2018.
But the country’s anti-discrimination law explicitly covers only discrimination committed on the basis of race.
Brazil’s Senate is debating legislation that would punish hate crimes based on sexual orientation or gender with up to five years in prison, but could leave room for religious exceptions.
With the court vote, the judiciary got out in front of the slow-moving legislation.
"Parliament doesn’t act,” said Judge Luiz Fox, who cast the sixth and deciding vote.
“There is no guarantee the bill will pass, and even if it does, it can be vetoed and homophobia will continue,” he said. “The judiciary must act in defence of minorities against violence by the majority.”
On the eve of the vote, pro-LGBT+ actors and musicians faced off against Brazil’s powerful evangelical lobby in the halls of the Supreme Court, as both groups tried to sway judges.
“Freedom of thought has to be protected,” Deputy Marco Feliciano, a member of the evangelical caucus in Congress, said before the hearing.
“But things are different today,” he continued. “The church isn’t confined behind four walls. A pastor can go to the pulpit and say ‘homosexuality is a sin, it scars divine character’.
“That’s religious liberty, guaranteed by article five of the constitution,” he said. “But what if someone takes a video of that and posts it on social media?”
A push by the evangelical caucus to delay the vote did not gather enough support.
While the country’s religious right has made significant inroads in Brazil’s congress, Brazil’s supreme court judges, most of whom were appointed by left-leaning presidents, remain staunchly pro-LGBT+.
Felipe Daier, a lawyer who researches LGBT+ rights, praised the court’s decision, but said more must be done.
“It is extremely important that this criminalisation be accompanied by actions that allow for gender education in schools and by a reduction in inequality in all areas of public policy,” he said.
More about: Brazil