A man has been charged in connection with a home invasion last week on the Northwest Side that allegedly ended with him shooting his accomplice to death.

Slobodan Pesovic, 31, was charged Thursday with felony counts of home invasion involving the discharge of a firearm and first-degree murder while committing another forcible felony, according to Chicago Police.

Pesovic appeared in court Friday and was denied bail.

The home invasion happened about 9:50 p.m. Jan. 30 in the 2400 block of West Eastwood in the Ravenswood neighborhood just south of Lincoln Square, police and the Cook County State’s Attorney’s Office said.

Pesovic and 43-year-old Luis Antonio Morales were co-workers at a restaurant and decided to try and rob the resident — who owns a different restaurant — because they believed he kept a large amount of cash inside the home, authorities said.

Prosecutors said Friday that the 70-year-old man who lived at the home did not know either of the two intruders.

Surveillance cameras captured Pesovic and Morales leaving work together before the robbery, prosecutors said. They knocked on the door of the home, which was answered by the 70-year-old, who had been in the kitchen talking with his 69-year-old wife, and believed other members of his family were at the door. The couple’s 37-year-old son was upstairs.

When the door was opened, Pesovic and Morales forced their way inside and pushed the 70-year-old to the ground, prosecutors said. Morales pulled a gold chain from the man’s neck as he cried out. Hearing the commotion, his son came downstairs to confront the two intruders and began to struggle with Morales.

Pesovic, who would later describe Morales as his best friend to a witness, fired five times into the home, accidentally striking Morales four times, prosecutors said. The family ran to an upstairs bedroom, where they waited for police to arrive, and were not hurt.

Morales, who lived in Melrose Park, suffered gunshot wounds to his mouth, chest and arm, authorities said. He was pronounced dead at the scene.

Prosecutors said Pesovic ran away after shooting, discarding the mask and gloves he was wearing for the robbery along his route. They were subsequently recovered by investigators.

When Pesovic arrived for work the next day, his co-workers told investigators that he was visibly distraught and had cuts on his hands, prosecutors said. He was sent home for the day.

Pesovic, who lives in the Cragin neighborhood on the Northwest Side, had a prior felony conviction for a domestic battery, authorities said. His court-appointed attorney said he was the father of two children.

He was scheduled to return to court Feb. 13.