A man lauded as a hero for confronting a shooter inside an Oregon grocery store Sunday was convicted of child sex crimes while in the Army decades ago.

Donald Surrett, Jr. died while trying to stop 20-year-old Ethan Blair Miller’s shooting rampage. Police said Surrett’s decision cost him his life but likely saved the lives of others.

OREGON DAD DETAILS HOW HE AND HIS 4 CHILDREN ESCAPED SAFEWAY SHOOTING: ‘BY THE GRACE OF GOD’ 

According to military and Oregon State Police records, Surrett in 1994 pleaded guilty to two counts of carnal knowledge and two counts of indecent acts while he was serving in the U.S. Army, Oregon Public Broadcasting reported. He was 38 at the time, and served 26 years in the military.

A military court sentenced Surrett to 10 years in prison at Fort Leavenworth, Kansas.

Donald Surrett, Jr. was previously convicted of child sex crimes.

Donald Surrett, Jr. died while trying to stop a shooting rampage at a Safeway grocery store in Bend, Oregon.

U.S. Army spokeswoman Madison Bonzo said Surrett was demoted from sergeant first class to private as a result of the conviction. He did not serve the entire sentence, and moved to Oregon in the early 2000s, according to public records.

Deschutes County District Attorney John Hummel confirmed Surrett was convicted of an "indecent act with a minor" in a military court.

BEND, OREGON, SHOOTING: 66-YEAR-OLD SAFEWAY EMPLOYEE TRIED TO DISARM SHOOTER, MAY HAVE SAVED LIVES, POLICE SAY 

Information from state court records and the Oregon State Police’s sex offender registry indicates Surrett did not reoffend after his prison release, and law enforcement considered him a Level 1 offender, the lowest classification in the state and an indication he was not considered a high risk for reoffense.

Video shows 66-year-old Surrett hid behind a produce cart until the gunman, who had near the store entry shot and killed 84-year-old Glenn Bennet, looked the other way and then attacked him with a knife, police said.

The shooter killed himself as police entered the building.

BEND SHOOTING: SAFEWAY EMPLOYEE 'ATTACKED THE SUSPECT WITH A PRODUCE KNIFE HE KEPT ON HIS HIP,' POLICE SAY

Sheila Miller, a Bend Police Department spokeswoman, told OPB that police learned of Surrett’s criminal history as they investigated the shooting.

"Mr. Surrett’s background does not change the fact that in this instance, when faced with great peril, he acted heroically in attacking and attempting to disarm an active shooter in his place of work," Miller said. "While Mr. Surrett’s past may complicate how people feel about his legacy, his actions in the moment were courageous and for those actions, he deserves praise."