The parents of a 9-month-old girl who was shot in the hip at her home in Brooklyn were charged on Sunday in connection with the shooting, the police said.

The girl’s father, Pedro Rosales, 47, was cleaning a gun on Saturday in the family’s apartment at 580 Sutter Avenue in East New York around 4 p.m. when it fired accidentally, striking his daughter, Jessica, the police said.

Mr. Rosales was charged with assault, reckless endangerment, acting in a manner injurious to a child and criminal possession of a weapon, the police said. The girl’s mother, Jessica Aguilar, 24, was charged with reckless endangerment and acting in a manner injurious to a child.

The bullet entered the girl’s hip and exited from her back. She was initially taken to Woodhull Medical and Mental Health Center in Brooklyn and then transferred to Bellevue Hospital Center, where she underwent surgery on Saturday. She was expected to survive, the police said.