When Juan Manuel Correa Leyva was shot and killed after allegedly shooting a deputy in the leg at a traffic stop earlier this month, he had been out of federal prison for only two months, records show.

Correa Leyva, a 27-year-old U.S. citizen, spent time in federal prison after a 2012 drug-smuggling bust at the U.S.-Mexico border in Nogales and again in 2016 after an arrest near Casa Grande for smuggling an illegal border-crosser, according to U.S. District Court records.

The July 17 fatal shooting came after Correa Leyva tried to flee from Pima County sheriff’s Deputy Jose Velasco, dragging him along the road near East Ajo Way and South Country Club Road.

Velasco was able to get back onto his patrol motorcycle and catch up to Correa-Leyva, the sheriff’s department says.

Velasco was approaching Correa Leyva’s car when Correa Leyva began firing and shot Velasco in the leg. Velasco returned fire, killing Correa Leyva. Velasco continues his recovery, but it is unclear when he will return to work, department spokesman Deputy James Allerton said Thursday.

Federal Bureau of Prisons records show Correa Leyva was released from prison May 22.

The prison sentence came after he was arrested driving an illegal border-crosser from Nogales to Los Angeles, according to a criminal complaint. He was pulled over for speeding in Pinal County; the Mexican man Correa Leyva was driving told a Border Patrol agent that he had crossed the border illegally.

In 2016, Correa Leyva pleaded guilty to human smuggling and was sentenced to 24 months in prison and 36 months supervised release.

In 2012, Correa Leyva was crossing the border in downtown Nogales when a narcotics-detection dog alerted to Correa Leyva’s vehicle, according to a criminal complaint. When agents inspected the vehicle, they found 13 packages of cocaine in a hidden compartment .

He was to be paid $2,500 if he successfully transported the drugs and planned to use the money to buy clothing for his daughter, rent a home and buy a car for his wife, according to a sentencing memorandum filed by his defense lawyer.

Correa Leyva was sentenced to 52 months in prison for attempting to smuggle 33 pounds of cocaine into the United States.

After his release in October 2014, Correa Leyva was placed at a drug-treatment center in Tucson. Two months later, a staff member saw him leave the treatment center without permission, carrying his belongings. He did not return, according to a criminal complaint.

He was sentenced to four months in prison and 36 months supervised release for his escape from the treatment center.

Pablo Lopez is a journalism student at the University of Arizona and an apprentice at the Arizona Daily Star. Contact him at starapprentice@tucson.com