ISLAMABAD — Nine-month-old Mohammad Musa will not be going to prison on attempted-murder charges.

The Pakistani baby drew international attention in recent days when police took the unusual step of charging him along with four adults — including his father and grandfather — in connection with a violent protest in Lahore. Critics say the charges reflected the tendency of the Pakistani police to lodge exaggerated complaints against poor families.

The case led to widespread ridicule being heaped on the Pakistani legal system, particularly after little Musa was photographed crying while being fingerprinted. His family subsequently moved him out of Lahore to Faisalabad, citing safety reasons.

Judge Rafaqat Ali Qamar dismissed the case against Musa during a hearing Saturday in which police said they would no longer pursue the charges, defense lawyer Irfan Tarar said.

Qamar also reprimanded police, demanding a written explanation about why officers did not properly investigate the case, Tarar said.

The case stemmed from an incident Jan. 31, when power company officials went into the boy’s neighborhood to disconnect illegal power lines allowing people to get electricity to their homes without paying for it. Such pilferage is common in Pakistan, and attempts to disconnect customers can be met with violence.

Police said that in this case, neighbors threw stones at energy company officials and their officers. The boy’s grandfather, Malik Muhammed Yaseen, said earlier that neighborhood women attacked the police with batons only after officers mistreated residents.

That altercation sparked police to open an attempted-murder investigation into 30 people in the neighborhood, including little Musa, police officer Atif Zulfiqar said last week.

The case highlighted the country’s dysfunctional criminal-justice system, where even children are not immune. Pakistan’s police, widely criticized as improperly trained and ill-equipped, are routinely accused of torturing suspects and extorting people for bribes. Flaws in the country’s legal system and poor police investigations often see criminals and terrorists released, while militants routinely target officers in their attacks.

Tarar said the child’s family was very happy.

“After today’s court order, the 9-month-old boy is free to live anywhere,” he said. “This case is an eye opener, and we hope and expect that police will avoid any repeat of such mistakes.”

The status of the rest of the case remained unclear on Saturday.