Edgar Martinez, 20, was charged with first-degree murder, aggravated assault and unlawful use of a weapon. View Full Caption DNAinfo; Chicago Police Department

COOK COUNTY CRIMINAL COURTHOUSE — A West Ridge man was charged with murder after apparently shooting a fellow gang member in the back, prosecutors said Monday.

Edgar Martinez, 20, appeared in bond court Monday on charges of murder, aggravated battery with a firearm and unlawful use of a weapon by a felon.

Prosecutors allege Martinez was in a car with Daniel Rivera, 27, and Rivera's cousin shortly before midnight on May 23. Martinez and Rivera are both Latin Kings, according to authorities.

Rivera told his cousin, who was driving, to pull into an alley in the 4700 block of North Troy Avenue about 11:40 p.m., Assistant State's Attorney Jennifer Keating said during a bond hearing Monday.

Martinez and Rivera got out of the car, walked toward a group of unarmed men, pulled guns and began shooting, prosecutors said. Keating pointed out that Rivera had been walking in front of Martinez when the pair opened fire.

Rivera was shot once in his back, and the man driving the car began to back out of the alley in reverse, prosecutors said. Rivera collapsed, and Martinez went to his body and grabbed what appeared to be a gun, according to Keating.

A witness who lives in the area heard gunshots and saw the car driving down the alley in reverse, prosecutors said. The witness allegedly saw a man run after the car, and heard a clanking sound of an object being dropped. Keating said surveillance cameras caught parts of the shooting on tape.

Police found Rivera, of the 7200 block of North Damen Avenue, unresponsive in the alley about 11:45 p.m. He was taken to Northwestern Memorial Hospital, where he was pronounced dead.

Police at the time said Rivera was shot in his face. But prosecutors on Monday said the Cook County Medical Examiner's Office recovered a bullet in Rivera's back. His death was ruled a homicide.

Officers on the scene found six 9-mm shell casings near Rivera's body, Keating said. Police searched the area where the witness heard a clanking sound and found two guns: a 9-mm gun loaded with five live rounds, covered in blood; and a 16-round-capacity .22 caliber revolver with six expended rounds in the cylinder.

The bullet pulled from Rivera's body matched the .22 caliber gun, Keating said.

Martinez was arrested this week after the witness positively identified him, according to prosecutors.

Rivera's cousin, who had been driving the car, was pulled over for a traffic violation about two miles from the scene about 15 minutes after the shooting, Keating said. The officer who stopped the car later identified Martinez as a man sitting in the front passenger seat at the time, Keating added.

Martinez, of the 6300 block of North Oakley Avenue, was previously convicted in 2012 of aggravated battery with a deadly weapon after he and two fellow gang members attacked with baseball bats a group of students returning a homecoming dance, prosecutors said.

Martinez also has a pending DUI case in Bridgeview, Keating added.

Cook County Judge Peggy Chiampas on Monday ordered Martinez held without bail.

For more neighborhood news, listen to DNAinfo Radio here: