It happened around 9:40 p.m. Wednesday on the 1700 block of S. Cleveland Street.
Family members told police the child was handling a gun when it went off and struck him once in the stomach.
Police said the bullet exited through his back.
The child's parents took him into their car and drove to Children's Hospital of Philadelphia. He was placed in critical condition and taken into surgery.
He was later upgraded to stable condition.
Police found a handgun in the upstairs bedroom on the floor next to a bed.
Philadelphia Police Chief Inspector Scott Small said the boy is very lucky to be alive.
"We were told he had a gunshot wound to his lower stomach that exited from his back...Just recently we were notified that that 2-year-old is now in stable condition and that nothing vital was struck," Small said.
It's still unclear how the child gained access to the gun.
In addition to the boy and his parents, police said there were two other adults and a 6-year-old child inside the home at the time.
Police said the boy's father, 34-year-old Saul Rosario, was charged with endangering the welfare of a child, violation of uniform firearms act and other related offenses.
Alexandra Aponte, 31, who is the boy's mother, was charged with endangering the welfare of a child and other related offenses.
Philadelphia Police Commissioner Danielle Outlaw released a statement Thursday morning saying, "Yet another one of our precious children has suffered a critical injury as a result of gunfire. While the manner in which the child was shot is still under investigation, it is already apparent that as a community, we must do everything possible to ensure that our children are safe in their homes."