DIXON, Ill. (AP) ā€” Authorities say the quick-action of a "heroic" school resource officer Wednesday thwarted a school shooting suspect in northern Illinois.

A 19-year-old suspected gunman was shot by a school resource officer Wednesday outside a high school in Dixon, Ill. after the suspect opened fire inside the school building, police said.

The officer confronted the armed man at the Dixon High School near the school gym, where seniors were gathering for a graduation rehearsal, after he had opened fire in the school.

The gunman, a former student at the school, ran out of the building after the school resource officer approached him, and the officer gave chase.

During the chase, the suspect fired several rounds at the school resource officer. The officer then returned fired at the gunman, who suffered non-life threatening injuries, said Dixon Police Chief Steve Howell Jr.

The suspect is in custody and is receiving medical treatment. No students or staff were injured in the incident.

"I could not be more proud of the police officer and the way he responded to the situation," Howell said. "With shots ringing out through the hallways of the school, he charged toward the suspect and confronted him head on. Because of his heroic action, countless lives were saved."

The officer, who was not named, was put on paid administrative leave per city policy after an officer-involved shooting.

The city, about 90 miles west of Chicago and best known as the hometown of former president Ronald Regan, said all city schools were put on lockdown following the shooting.

The ATF said that agents from its Chicago and Rockford, Ill. offices were dispatched to Dixon to help with the investigation.

Rep. Adam Kinzinger, R-Illinois, wrote on Twitter that he was briefed by local law enforcement officials on the incident.

ā€œI extend my deep gratitude to @DixonPolice, & the Officer on-site, for their swift action & for keeping our students & teachers safe,ā€ Kinzinger tweeted.

The incident comes three months after a school resource officer came under criticism for acting too slowly in the midst of a school shooting in Parkland, Fla., that left 17 dead.

The officer, who resigned in the aftermath of the Feb. 14 shooting, was slammed as a coward by President Trump after video surfaced showing him outside Marjory Stoneman High School during the massacre.

Howell said that students and staff at the school appeared to have acted coolly under stress during the incident. When officers arrived at the school, they found classrooms were barricaded with bookshelves and desks, as students and staff have been trained to do in active shooter situations.

"A lot of things went right today when a great many of them could have gone wrong," Mayor Li Arellano Jr. said.