COLUMBIA, S.C. — A South Carolina judge citing the state’s Stand Your Ground Act has granted immunity from prosecution to a man charged with shooting and killing an unarmed bystander.

“When the defendant fired the shot, he reasonably believed he was being attacked … at his home,” said a 12-page order by Circuit Judge Maite Murphy filed Wednesday afternoon.

The case involved the 2010 shooting of Darrell Niles, 17, a Keenan High School student, who was across the street in a car when Shannon Scott, then 33, fired his handgun.

Shortly before the incident that killed Niles, an SUV filled with youths who had been threatening Scott’s 15-year-old daughter drove by his house and they fired shots.

Scott then saw Niles’ 1992 Honda, and, believing its occupants posed a danger, fired his gun from his front yard across the street, hitting Niles in the head. No evidence indicated Niles was a threat.

According to Scott’s attorney, Todd Rutherford of Columbia, the law gives people in fear of their lives broad rights.