Image copyright CBS Image caption Jemel Roberson hoped to become a police officer himself, friends say

An armed security guard at a bar in suburban Chicago was killed by police as he detained a suspected gunman, according to officials and witnesses.

After gunfire erupted around 04:00 local time on Sunday, Jemel Roberson, 26, chased down an attacker and knelt on his back until police arrived.

Moments after police came on the scene, an officer opened fire on Roberson, who was black, killing him.

Friends say Roberson was a musician who had dreams of joining the police.

"The very people that he wanted to be family with took his life," Patricia Hill, the pastor of Purposed Hill church in Chicago, told WGN-TV.

Roberson worked as a gospel musician at several nearby churches, and also had found work at Manny's Blue Room in Robbins, Illinois, where the shooting occurred.

How did the shooting occur?

Sophia Ansari, a spokeswoman for the Cook County Sheriff's office, said police were called to the scene after a fight broke out in the bar and four people were shot.

Witness Adam Harris told Fox32 that Roberson, who was armed with a legally owned firearm, then chased down and caught one of the attackers.

"The security guard that got killed, he caught somebody and had his knee on him the whole time," Mr Harris said.

"Just waiting on the police to get there. I guess when the police got there, they probably thought he was one of the bad guys, cause he had his gun on the guy and they shot him."

"Everybody was screaming out 'security, he was a security guard'", Mr Harris added, "and they still did their job and saw a black man with a gun and basically killed him".

Images on social media show a chaotic scene outside the bar as witnesses shouted at police.

"He was protecting the club and holding a suspect down," Mr Harris told CBS.

The chief of the Midlothian police, whose officer fired the fatal shot, said in a statement: "Upon arrival officers learned there were several gunshot victims inside the bar."

Chief Dan Delaney continued: "A Midlothian officer encountered a subject with a gun and was involved in an officer-involved shooting."

Illinois State Police's Public Integrity Taskforce have been asked to investigate the shooting, Ms Ansari told the BBC.

She added that the other four who were shot - including the offender" - suffered injuries that did not appear to be life-threatening.

What is the reaction?

Acquaintances say Roberson was a spiritual man, who played organ at several churches in southern Chicago.

"How in the world does the security guard get shot by police?" New Spiritual Light Baptist Church Pastor Walter Turner told ABC7 News.

"A young man that was literally doing his job and now he's gone."

An online fundraiser set up for Roberson's burial expenses had raised over $12,000 (£9,300) as of Monday.

"Jemel was a gifted basketball player and musician, and his love for God and his family were at the forefront of his life," according to the GoFundMe page.

"Sadly, Jemel's life was tragically and unexpectedly cut short this morning as he tried to save others from senseless violence."

According to FBI data, a disproportionately high proportion of police shootings in the US involve black people.