Less than a month before two deadly shootings claimed the lives of 31 people in El Paso, Texas, and Dayton, Ohio, a Texas grandmother stopped another mass shooting before it began.

William Patrick Williams, a 19-year-old from Lubbock, Texas, told his grandmother that he had purchased an AK-47 rifle and planned to "shoot up" a local hotel and "commit suicide by cop," according to the U.S. Attorney’s Office of the Northern District of Texas.

Concerned for his safety and for the safety of others, she convinced her grandson to let her take him to a local hospital, a news release said.

During the investigation, federal agents discovered Williams had "misrepresented" his current address on the firearms transaction form when he purchased the rifle. After a brief hospital stay, he was arrested Thursday on suspicion of making false statements to a firearms dealer.

Rising death toll, police video and 'hundreds' saved:The aftermath of the El Paso, Dayton shootings

“This was a tragedy averted,” U.S. Attorney Nealy Cox said in the release. “I want to praise the defendant’s grandmother, who saved lives by interrupting this plot, as well as the Lubbock police officers and federal agents who investigated his unlawful acquisition of a deadly weapon.”

Officers searched the room Williams rented at the hotel he planned to target and found the rifle, 17 loaded magazines and multiple knives. Williams told authorities he laid out his weapons so that they could take them.

'Those who died in Toledo':Trump mixes up Ohio cities while giving remarks on mass shootings

Other items found during the search included a black trenchcoat, black tactical pants, a black T-shirt that read “Let ‘Em Come,” and black, fingerless tactical gloves.

Williams could face up to five years in federal prison if convicted, according to the release.

"If you suspect a friend or loved one is planning violence against themselves or others, do not hesitate to seek help immediately by calling law enforcement," Cox said.

El Paso Walmart shooting at Cielo Vista:What we know about the number of victims, the suspect

Walmart says it won't stop selling guns:In the wake of a mass shooting, some advocates say it should

Follow N'dea Yancey-Bragg on Twitter: @NdeaYanceyBragg