Mobile phones used by Jair Bolsonaro Brazil’s president were accessed by a group of hackers who also targeted a senior judge and prosecutors leading a sweeping anti-corruption investigation, Brazil’s far-right president said on Thursday.

The revelation came days after law enforcement officials took four people into custody as part of their investigation into the hacking of confidential material stored on the cellphones of Brazilian cabinet members, prosecutors, and lawmakers.

Mr. Bolsonaro called the hacking “a serious attack against Brazil and its institutions,” but said he had little to fear. “I never handled sensitive or national security matters over a cellphone,” and called for harsh punishment for the alleged hackers.

Police detective João Vianey Xavier Filho said the group hacked into the messaging apps of around 1,000 different cellphone numbers, but provided little additional information at a news conference in Brasilia on Wednesday. Cellphones used by Bolsonaro were among those attacked by the group, the justice ministry said in a statement on Thursday, adding that the president was informed of the security breach.

Economy Minister Paulo Guedes was another likely target as one of the arrested suspects had an account on his phone with Guedes’s name, Xavier said.

Police began investigating alleged hacker activity following the leaking of text messages between the anti-corruption judge turned Justice Minister Sergio Moro and the lead prosecutors in the Operation Carwash graft probe.

The publication of those private exchanges in The Intercept news website roiled the Brazilian government, raising questions about the impartiality of Moro, who sentenced former President Luiz Inacio Lula da Silva to prison for corruption and money-laundering. Moro has questioned the authenticity of the published material, while also maintaining that the texts show no wrongdoing and that he has been the victim of criminal hackers.

But the leaks have undermined the approval rating of one of the most popular figures in the administration of President Jair Bolsonaro, and government allies have threatened Glenn Greenwald, the American journalist who founded The Intercept, with arrest or expulsion from Brazil.

In the court order determining the arrest of the four suspects, Judge Vallisney de Souza Oliveira wrote that the hackers had accessed Moro’s Telegram messaging app, along with those of two judges and two federal police officers. The judge also directed Google, Microsoft, and Apple to provide suspects’ IP addresses, registration data, as well as all archives and data stored in the cloud.

Two of the suspects received hundreds of thousands of reais in their bank accounts over recent months, despite having monthly incomes totaling just 5,000 reais. The judge called for the funds received to be tracked to discover possible sponsors of the attack.

The newspaper Estadão, citing law enforcement officials, said the initial target of the hacking effort was a prosecutor who had charged Mr. Delgatti with drug trafficking in 2015. After accessing content from the prosecutor’s phone, news reports said, Mr. Delgatti was said to have obtained the numbers of other government officials and taken data from their phones.

A lawyer for Mr. Delgatti this week said his client suffered from “psychiatric problems” and was in a state of shock. He could not be reached for comment Thursday afternoon.