Nevada rancher Cliven Bundy could have spent the rest of his life in jail, but instead he walked away Monday a free man, the case against him and his sons thrown out over what the judge decried as “outrageous” misconduct by federal prosecutors.

In a stunning rebuke, U.S. District Court Chief Judge Gloria Navarro scolded the prosecution for violating the due process rights of the four defendants — Cliven Bundy, his sons Ammon and Ryan, and Ryan Payne — and dismissed the case “with prejudice,” meaning they cannot be retried on felony conspiracy and firearms charges stemming from the 2014 Nevada standoff.

“The court finds that the universal sense of justice has been violated,” said Judge Navarro, appointed to the bench by President Barack Obama in 2010, as reported by the Arizona Republic.

Wearing a cream-colored cowboy hat, the 71-year-old Bundy was greeted by cheers from dozens of well-wishers as he emerged from the federal courthouse in Las Vegas with his arm around his wife, Carol Bundy.

“How am I feeling? Well, I tell you, I’ve got my sweetheart beside me and I’m feeling pretty good,” said Mr. Bundy in video posted by KSNV-TV in Las Vegas. “I’m not used to being free, let’s put it that way. I’ve been a political prisoner for right at 700 days today.”

He insisted, “I come in this courtroom an innocent man, and I leave an innocent man.”

The dismissal brought a dramatic close to the high-profile case three weeks after Judge Navarro declared a mistrial, citing the prosecution’s willful withholding of evidence related to the armed standoff with the Bureau of Land Management at the Bundy ranch near Bunkerville.

The decision also comes as the latest and most devastating in a series of failures for the Justice Department in its ongoing battle against the Bundys and their supporters in trials in Nevada and Oregon.

In October 2016, an Oregon jury acquitted Ammon and Ryan Bundy, as well as five others, on felony conspiracy and firearms charges from their 41-day armed occupation of the Malheur National Wildlife Refuge.

Ammon and Ryan Bundy were also released on Monday, but Ryan Payne of Montana is expected to be transported to Portland, Oregon, for sentencing after entering a guilty plea for his role in the takeover.

Dayle Elieson, who took over as interim U.S. Attorney for Nevada on Friday, released a brief statement that gave no hint as to how the Justice Department would respond to the prosecutorial misconduct.

“We respect the Court’s ruling and will make a determination about the next appropriate steps,” she said in a statement.

Attorney General Jeff Sessions ordered an expert examination of the case on Dec. 20, the day Judge Navarro declared a mistrial, but the department has yet to release the results of the review.

Four more defendants await trial in Nevada

Also unclear is how prosecutors will proceed with the final phase of the three-tier trial in Nevada.

Four more men are scheduled to go on trial, the last of the 19 men charged with multiple felony counts for their roles in the standoff, which saw hundreds of Bundy backers descend on the ranch after BLM agents attempted to impound 400 head of cattle.

The BLM responded by cancelling the operation, triggered by Cliven Bundy’s longstanding refusal to pay about $1 million in grazing fees and fines to the federal government in a protest against public-lands policy.

In the first trial, which began in February, the judge was forced to declare a mistrial after the jury deadlocked on most charges against the six defendants. Two were found guilty of weapons and obstruction counts.

The four others were retried, resulting in the jury acquitting two defendants on all charges and the other two on most counts, but deadlocking on other charges. Six other participants have entered into plea deals.

The trial’s third tier is expected to begin next month, but Ryan Bundy said he wanted to see the judge free remaining defendants, who include two more Bundy brothers, David and Melvin.

“The government has acted wrongly from the get-go,” Ryan Bundy told the Las Vegas Review-Journal.

Judge Navarro admonished the government for “flagrant prosecutorial misconduct” and withholding “potentially exculpatory” evidence, including FBI logs on surveillance and sniper activity, threat-assessment reports indicating that the Bundys were not dangerous, and internal reports about misconduct involving BLM agents.

Outside the courthouse, Cliven Bundy said that he had a “15-second defense: I grazed my cattle only on Clark County, Nevada, land, and I have no contract with the federal government.”

He criticized local government officials, including the Clark County sheriff, asking why they allowed federal officers to “come in with an army against us and stick their guns down our throat?”

“Am I mad at the federal government? I am not mad at the federal government,” said Mr. Bundy. “I am mad at my local government that’s supposed to protect my life, liberty and property. My county commissioners, my governor and my county sheriff.”

Ian C. Bartrum, professor at the University of Nevada Las Vegas law school, said he was struck by the judge’s reproof, noting that “she didn’t mince words in her criticism of the government,” and characterized the dismissal as a clear victory for the Bundys and their fight against federal lands policy.

“The judge’s decision plays like a vindication for at least part of the Bundy’s claims — that the government has been overzealous from the beginning on this case,” said Mr. Bartrum in an email. “The roundup was overkill, the charges were overkill, and the prosecution’s behavior was, in the judge’s words, ‘outrageous.’ That’s a pretty big win for the Bundys politically, which is where all the land stuff will eventually play out.”

Kieran Suckling, executive director of the Center on Biological Diversity, blamed the Justice Department for bumbling the prosecution.

“Federal prosecutors clearly bungled this case and let the Bundys get away with breaking the law,” said Mr. Suckling in a statement. “The Bundys rallied a militia to mount an armed insurrection against the government. The failure of this case will only embolden this violent and racist anti-government movement that wants to take over our public lands.”

The Bundy Ranch page on Facebook posted a photo late Monday of Cliven and Carol Bundy kissing outside their home next to an American flag.

“Aww,” said the post. “He is back on the ranch and in the arms of my momma! GOD IS GOOD! Now let us get back on our knees and thank our Heavenly Father!”