Deputies say Brady Joseph Ray was trying to break into his ex-wife's house before she called authorities.
"He was texting me while I was away. I thought I was only calling the cops for breaking and entering, and then it escalated," his ex-wife said.
The deputy responded to the home on Plantation Tree Court near West Little York on Friday evening.
When the deputy arrived, he was allegedly met with gunfire from Brady. Investigators say the deputy was shot in his leg.
A neighbor's surveillance camera picked up the sounds of the bullets flying in the middle of the night. About 17 shots could be heard from the video.
Shortly after the deputy was shot, another deputy arrived and transported him to Methodist Hospital in Katy. He's in stable condition after receiving surgery.
"Please keep our HCSO deputy in your prayers. He was shot while responding to a call for service. He sustained a gunshot wound to his upper leg and is currently hospitalized," Sheriff Ed Gonzalez tweeted.
After an hours-long search, deputies found and arrested 39-year-old Brady. He has been charged with aggravated assault serious bodily injury, aggravated assault on a police officer and burglary of habitation with intent to commit assault.
Update on Plantation Tree Ct: Brady Joseph Ray is the person of interest in our investigation. Ray is described as a white male, 39yrs, 5’11”, medium build, wearing black shorts, gray shirt. Ray was armed with a pistol. #HouNews pic.twitter.com/O4ZCNpsXvl— Ed Gonzalez (@SheriffEd_HCSO) June 15, 2019
His ex-wife told ABC13 that Brady has never been arrested before.
"I recently divorced him and he hasn't taken it well at all despite all my efforts to make this a peaceful divorce," his ex-wife said.
Ray's bond was set at $2.5 million.
Follow Katherine Marchand on Facebook and Twitter.