A Texas judge dismissed the National Rifle Association’s Chapter 11 bankruptcy petition on Tuesday, dealing a major setback to the gun rights group amid an ongoing legal fight in its home state of New York.

U.S. Bankruptcy Judge Harlin Hale’s ruling effectively scuttles the NRA’s push to relocate from New York to Texas. The judge determined the group "did not file the bankruptcy petition in good faith" and deemed the filing was a bid to avoid a state regulatory crackdown.

"The question the court is faced with is whether the existential threat facing the NRA is the type of threat that the Bankruptcy Code is meant to protect against," Hale wrote. "The court believes it is not."

New York State Attorney General Letitia James filed suit in a bid to dissolve the group amid allegations of financial impropriety. The suit alleged that top NRA officials, including Executive Vice President Wayne LaPierre, funneled millions of dollars from the organization for personal use and improperly awarded contracts to friends and associates.

The NRA has denied the allegations laid out in the lawsuit and argued the legal action is politically motivated.

James’ office and attorneys for Ackerman McQueen, the NRA’s former advertising agency, had asked the court to dismiss the Chapter 11 petition, arguing the bankruptcy filing was an effort to evade legal action in New York. James lauded the judge’s decision.

"A judge has ruled in our favor and rejected the @NRA's attempt to claim bankruptcy and reorganize in Texas," the New York attorney general wrote. "The @NRA does not get to dictate if and where it will answer for its actions, and our case will continue in New York court. No one is above the law."

CLICK HERE TO GET THE FOX NEWS APP

The NRA is headquartered in Virginia but incorporated in New York. The nonprofit filed for Chapter 11 bankruptcy last January in a bid to reincorporate in Texas. At the time, the NRA argued that New York was a "a corrupt political and regulatory environment."

The judge’s ruling did not prohibit the NRA from filing for bankruptcy a second time. However, the court noted that another filing could prompt the appointment of a trustee to oversee the NRA.