A plot by a "disgruntled" student who was planning a mass shooting within weeks at a Southern California high school was thwarted after a security guard overheard a conversation last week, authorities said Wednesday.

Los Angeles County Sheriff Jim McDonnell said at a news conference that a security guard at El Camino High in Whittier, east of Los Angeles, overheard the 17-year-old student on Friday threaten to open fire in a matter of weeks.

"Parents, this should be a wakeup call; please talk to your kids," McDonnell said. "We owe students, parents and teachers our gratitude for providing these leads."

The sheriff said the weapons found at the teen's home included two AR-15 rifles and 90 high-capacity magazines.

McDonnell called the school security officer, Marino Chavez, an "unsung hero" for alerting authorities.

Chavez said the teenager made the comments at a lunch break on Friday, after he had a disagreement with a teacher because he'd brought headphones to school. Students are not allowed to have electronic devices out during class time.

The security guard then confronted the teenager and asked him what he meant, to which the teenager replied there would be a school shooting "within three weeks" on campus.

WOMAN WHO CARED FOR FLORIDA GUNMAN REPORTEDLY WANTS TO CONTROL HIS INHERITANCE

Chavez said the teen said he'd been kidding, but he still brought the youth to the main office to report the incident.

"Parents, this should be a wakeup call; please talk to your kids." — Los Angeles County Sheriff Jim McDonnell

"There was swift action that could have possibly prevented a tragic event," he said at a news conference, adding that he was "just doing my job."

The student, who has not been identified because he is a minor, was arrested on charges of making criminal threats, according to McDonnell.

Robert Jacobsen, the general counsel for the Norwalk-La Mirada Unified School District, told the Whittier Daily News there are usually three safety officers at the school.

El Camino High is a small alternative school, with more than 200 students enrolled, he told the newspaper.

McDonnell said one of the AR-15s was registered to the 17-year-old's older brother, while the other was not. The 28-year-old brother, whose name has not yet been released, was arrested on separate weapons charges, according to the sheriff.

The student has previously faced disciplinary action at the school, and was previously suspected of saying he wanted an administration dead. In that incident, the sheriff said the boy's mother told police her son had issues but was not a threat.

The sheriff said in light of the recent mass shooting at a South Florida school that left 17 people dead, the actions by the officer show that "we all have to do this together" to stop potential violence in schools.

"This is something that could have gone down that path, but didn’t due to the work of the Norwalk school district," McDonnell said, referring to the Florida shooting.