When Felipe Ramirez Castellanos stood in front of an immigration judge in Arizona last April, the end of his time in the U.S. must have seemed near.

With an immigration history that included arrest for human smuggling and a denied visa application, Castellanos was brought before the judge after a traffic stop in Pinal County. Without money to pay the $7,500 bond, some combination of prison and deportation was likely on the horizon.

Instead, Castellanos walked out of the courtroom pending a removal hearing that never occurred.

Within nine months, Castellanos was dead, shot at close range by a Maricopa County sheriff's deputy in front of the east Mesa home Castellanos shared with his family.

Sheriff Joe Arpaio believes Deputy Miles Antwiler was protecting the public when he held his service revolver near Castellanos' head and pulled the trigger, the bullet entering Castellanos' skull between his eye and his ear and lodging in his brain.

Castellanos died at the Maricopa Medical Center two days later.

"I think the deputy is probably a hero," Arpaio said. "He might have saved a lot of lives that night."

The night began normally for the Castellanos family, according to a detective's interview with Juana Ramirez, Castellanos' wife. But after the children went to bed, Ramirez said she began questioning Castellanos about his drug use. He became angry.

As he left the house, he fired at least two gunshots into the air, startling the neighbors, who called 911.

Sheriff's deputies swarmed to the area. Castellanos left, then came back to his house about the same time Antwiler arrived. Castellanos backed his car out of the driveway, ignoring the deputy's orders, according to Antwiler's statement.

Antwiler got out of his car as Castellanos sat idling in the cul-de-sac. According to a neighbor who saw the incident, Antwiler walked toward Castellanos' SUV, shouting for him to stop.

When Antwiler got to the SUV, Castellanos rolled down the window and raised an assault rifle with the muzzle up. Antwiler saw the rifle and fired off three rounds before his gun jammed.

When paramedics pulled Castellanos' body from his SUV, they found his assault rifle with more than 30 rounds of ammunition and a handgun.

"The guy comes out of a house with all that firepower and gets in a car and points a gun at my deputy. What was he (the deputy) supposed to do?" Arpaio asked.

The events that unfolded Jan. 14 on East Crescent Avenue, a working-class neighborhood of homes surrounded by chain-link fences, ended Castellanos' 25-year journey through the U.S. immigration system.

Castellanos was first arrested in January 1986 and charged with transporting illegal immigrants into the United States, according to records released through the Sheriff's Office.

More than a decade later, Castellanos was lawfully admitted to the country as a non-immigrant - a designation that allows someone to remain legally for a specific purpose, such as work or school, and for a determined period of time.

Like many, Castellanos "remained unlawfully present in the United States after his permit expired," the files state.

While Castellanos was in the country unlawfully in 2001, he applied for a visa, which was denied in 2004. Castellanos would not have a problem with his immigration status again until he was with two others who were stopped in Pinal County in April 2010 for speeding and passing cars in the right-hand-turn lane.

Immigration and Customs Enforcement agents picked up Castellanos from the traffic stop and took him to a U.S. detention center. Less than two weeks later, he was released from custody after the immigration hearing.

Representatives from the Executive Office for Immigration Review did not return requests for comment Thursday about Castellanos' case, but federal officials have been consistent in their stance that factors such as prior deportation orders, criminal histories and family ties in the United States weigh heavily on whether a person is held in custody while removal proceedings are pending.

Castellanos never made it back to his immigration hearing.

Castellanos' wife told investigators she believed that her husband had a mental disorder and that he was paranoid, believing the police were following him.

"She has had numerous conversations with her husband about this situation and told him that no one was following him," the sheriff's report said. "She said he reacted by becoming quite angry and would have an outburst that people did not believe him and thought he was crazy."