A judge in Brazil has ruled that jailed former President Jair Bolsonaro can be placed under house arrest for the next three months because of poor health.

Bolsonaro, 71, was taken two weeks ago from his cell to a private clinic, where he was diagnosed with pneumonia and treated in an intensive care unit.

He has since been discharged from intensive care but his lawyers have argued that his recurrent health problems, many of which stem from a knife attack he suffered in 2018, warrant him being granted house arrest for humanitarian reasons.

Bolsonaro, who governed from January 2019 to December 2022, was sentenced to 27 years in jail for leading a conspiracy aimed at keeping him in power.

Previous requests by his lawyers to allow him to serve his sentence at home were rejected, but Supreme Court Justice Alexandre de Moraes has granted the request for an initial period of 90 days from the day of his discharge from the hospital.

Moraes said that after that period, Bolsonaro's situation would have to be re-assessed. The judge also ordered that the former president wear an ankle monitor.

Bolsonaro spent some time under house arrest after his conviction in September, but was later moved into a police cell after attempting to remove his ankle monitor.

The judge ruled that Bolsonaro represents a flight risk and laid down strict parameters for his house arrest, barring him from using phones or social media. He can only receive visitors from family, lawyers, and medical personnel.

Since his incarceration, Bolsonaro has publicly endorsed his son, Flávio, as his preferred candidate for the upcoming presidential elections, where Flávio is gaining popularity in the polls.