A teenage boy was accidentally shot and killed by his cousin inside a church Tuesday night in southwest suburban Wilmington, authorities said.

The boys, ages 15 and 17, were in a bedroom of the residence connected to the Christian Faith Center at 11:43 p.m. in the 1800 block of South Water Street when they heard what they thought was someone trying to break into the church, according to the Will County sheriff’s office.

They went to a closet that held firearms and retrieved a rifle, according to the sheriff’s office. The older boy had the rifle and was running toward the gymnasium where the sound was coming from.

The 15-year-old, identified as Michael Wilkey of Godley, was in front of the 17-year-old, who tripped over an extension cord attached to an industrial fan, according to the sheriff’s office. The older boy fell and the rifle accidentally discharged, striking the younger boy.

When deputies arrived, they found Wilkey unresponsive in the main area of the church with a single gunshot wound to an armpit, according to the sheriff’s office. He was taken to Riverside Hospital in Kankakee, where he was pronounced dead.

The older boy was brought into the investigations division, where he fully cooperated with detectives, according to the sheriff’s office. He is the son of the church’s pastor, and the family had recently moved into the residential part of the property.

The shooting was determined to be a “tragic accident” and the boy, who has a valid FOID card, was released without being charged.