The father of a young boy who was dangling from a balcony in Paris was out shopping and playing Pokémon Go while his son almost fell out of a building, authorities said.

The father will be charged with missing in action, police said.

The boy was saved by a migrant from Mali, who scaled the apartment building to rescue him. Mamoudou Gassama, who was in France illegally, climbed five stories, moving from balcony to balcony, and whisked the 4-year-old boy to safety on Saturday night as a crowd below screamed in horror. His actions went viral on social media, where he was dubbed “Spiderman.”

The unnamed father was detained overnight for alleged parental neglect, and is set to appear in court in September.

He left the child alone while he shopped, then lingered to play Pokémon Go, Prosecutor François Molins told BFM-TV.

The boy’s mother was not home, either, Molins said, according to ABC News, because she was visiting France’s Réunion Island in the Indian Ocean with relatives.

“He took a long time to return home because he had decided to play the smartphone game Pokémon Go when he left the store,” Molins told BFM-TV. “He is devastated because he realizes what he did, and the tragic consequences that it could have led to.”

President Emmanuel Macron on Monday lauded the 22-year-old as a hero, and rewarded the young migrant’s bravery with an offer of French citizenship and a job as a firefighter.

Gassama also received a gold medal from the French state for “courage and devotion.”

“I just didn’t have time to think, I ran across the road to go and save him,” Gassama told Macron during the meeting, as Fox News previously reported. “I just climbed up and thank God — God helped me. The more I climbed, the more I had the courage to climb up higher — that’s it.”

Gassama said he has authorization to stay legally in Italy, which is where he landed in Europe in 2014 after more than a year in Libya and a trip across the Mediterranean Sea. He came to France in September to join his older brother, who has lived in France for decades.

Gassama told Macron he was arrested and beaten during his long rough stay in Libya, “but I wasn’t discouraged.”

The French president said Gassama’s actions made him deserving of special treatment. Working as a firefighter corresponds with his skills, Macron said.

“You have become an example because millions have seen you” on social media, the president said.

Macron is behind a bill toughening French immigration law, and he stressed there is no contradiction between rewarding Gassama for his act of bravery and working to prevent migrants from entering France illegally by stopping the stream of arrivals at its source.

“An exceptional act does not make policy,” he told reporters later, vowing to maintain a policy that is “exigent, respectful of our principles” on asylum and “rigorous” regarding the migratory flux.

The special treatment for Gassama comes as authorities prepare to evacuate some 2,400 migrants from makeshift encampments in the French capital. The forced closure of the encampments is the subject of a heated debate between the Paris mayor, who wants to ensure the uprooted will be sheltered, and Interior Minister Gerard Collomb, who was present Monday at Gassama’s meeting with Macron.

The Associated Press contributed to this report.