Ralph Esper, 28, was charged after authorities said he pulled a gun on a man at a gas station Saturday. View Full Caption Chicago Police Department

COOK COUNTY CRIMINAL COURTHOUSE — A man being robbed at gunpoint in Greater Grand Crossing on Saturday managed to grab his attacker's gun and shoot him in the back during a struggle, prosecutors said.

The attacker ran off, only to turn up a few hours later at Stroger Hospital, where he told police he'd been the victim of a shooting, according to Assistant State's Attorney Erin Antonietti.

Ralph Esper, 28, was charged after authorities said he walked up to a 38-year-old man at a gas station in the 6600 block of South State Street on Saturday, pulled a gun and demanded money.

After the victim handed over an undisclosed item, he made a move for the gun, Antonietti said. During a brief struggle, the gun went off and Esper was shot in his back, court records show.

Esper ran off, and the victim gave the gun, a .22-caliber Taurus Ultralight, to police. Antonietti said officers recovered six live rounds and two spent rounds.

A few hours later, Esper showed up at Stroger Hospital, where he was treated for his wound. Antonietti said there were several inconsistencies in Esper's story, but police ultimately released him. Esper arrived at the hospital before a description of the gas station attacker had been released to police.

Esper was arrested late Sunday and charged with felony attempted armed robbery, unlawful use of a weapon and disorderly conduct. He was also hit with misdemeanor charges when officers found $48 worth of marijuana on him.

According to Antonietti, the victim and two witnesses positively identified Esper as the attacker.

On Monday, Judge Donald Panarese Jr. ordered Esper, who lives in the 5200 block of South Michigan Avenue, held in lieu of $400,000 bail.

For more neighborhood news, listen to DNAinfo Radio here: