A Texas state representative is lucky to be alive after a stray bullet hit him in the back of the head while he and his family celebrated New Year’s Eve. It came within millimeters from piercing his brain.

Rep. Armando Martinez, a Democrat who is in his seventh term serving District 39, was celebrating the New Year at a friend’s house in Weslaco, Texas, when he got shot with the stray bullet. In a phone interview with NBC Latino, Martinez said the partygoers had huddled inside the garage when they heard celebratory gunshots ring through the lower Rio Grande Valley.

State Rep. Armando Martinez, D-Weslaco, in an image taken on Feb. 2, 2005, in Austin, Texas. Deborah Cannon / AP, file

"At about 12 a.m., when the gunshots subsided, we walked outside with the kids to pop off some fireworks," Martinez said, while he recovered at the Valley Baptist Medical Center. "I was telling the kids to be careful and to not get burned. My wife came over, gave me a kiss and wished me a Happy New Year."

When she pulled away, that is when the stray bullet pierced Martinez's skull.

"I felt like I got hit by a sledgehammer," Martinez said. "I ducked and then walked into the garage to get some ice. I was in a lot of pain. When my wife took a picture and said there was a hole, I knew it was a bullet."

The Morning Rundown Get a head start on the morning's top stories. This site is protected by recaptcha

Martinez said he is "incredibly grateful" to the Weslaco firefighters and local paramedics for helping him get to a local hospital. A trauma and neurosurgeon removed a .223 caliber bullet from Martinez's head in a 45-minute medical procedure. The Hidalgo County Sheriff's Office is working on locating the source of the bullet, which could have come from a person firing a gun in the air two blocks away.

RELATED: Supreme Court Upholds Wide Reach of U.S. Gun Ban for Domestic Violence

"I was extremely lucky," Martinez said. "My surgeons said if it went a couple more millimeters deeper, I may not have been able to have this conversation right now."

Martinez, who was born and raised in Weslaco, explained that hearing gunshots from surrounding ranches during celebrations was common as he grew up. Over the years Weslaco's population has grown larger and denser, which has made some people nervous about their children playing outdoors during times like New Year's.

"This whole thing is going to be a start to putting a stop to people firing their guns in celebration," Martinez said. "The Valley was not as populous it is now. We have these subdivisions everywhere now. Especially after what happened on New Year's, it shows that someone can be hurt, and it can be tragic."

In his years serving his district, Martinez has worked extensively on bills relating to education, such as his HB-44 which would help establish a law school in the Rio Grande Valley. He has not worked on any legislation that would impose restrictions on gun ownership. After the incident, however, he is looking to take steps to prevent another accident.

RELATED: New Texas Law Allows College Students to Carry Guns on Campus

"It is something we are going to have to look at," Martinez said. "Our county Sheriff has done an excellent job working on this, and he is in touch with the District Attorney. We are going to look at what type of legislation we are going to offer this session."

Martinez said he expects to be going back home on Monday. He said that even though he was shot, he is thankful it did not happen to one of the children or to his wife.

"My biggest concern were the children," Martinez said. "Had my wife been any closer it could have been in her face or neck. The children saw everything happen."

"I do believe there is a silver lining that nobody else got seriously hurt," Martinez continued, "and I hope me and my family are in your prayers this year."

Follow NBC Latino on Facebook, Twitter and Instagram.