A Texas teen was arrested after his grandmother thwarted his plan to carry out a mass shooting at a local hotel, officials said.

William Patrick Williams, 19, was charged Friday with making false statements to a firearms dealer after telling his grandmother that he bought an AK-47 rifle, according to the US attorney for the Northern District of Texas.

The Lubbock teen allegedly told his grandmother July 13 that he planned to use the firearm to “shoot up” a local hotel and then force authorities to kill him.

Fearing the teen was homicidal and suicidal, the grandmother convinced him to enter a hospital for treatment instead, officials said.

He was briefly hospitalized before he was arrested Thursday for misrepresenting his address on forms to purchase the AK-47, according to prosecutors.

His rented hotel room was searched by officers who uncovered the AK-47 rifle, 17 magazines loaded with ammunition, multiple knives, a black trench coat, a black T-shirt that read “Let ‘Em Come,” and black fingerless gloves, prosecutors said.

“This was a tragedy averted,” said US Attorney Nealy Cox. “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. 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.”

Williams’ arrest came two days before the massacre Saturday at a Walmart in El Paso, Texas, about 350 miles southwest of Lubbock. The suspect, Patrick Crusius, was in custody after the shooting left 20 people dead and 26 others injured.

Another massacre followed less than 24 hours later when Connor Betts, 24, opened fire in Dayton, Ohio, killing nine people. He was killed by responding police.