Henry Lee McCollum wiped tears at a hearing Tuesday in Lumberton, N.C., where a judge declared him and his half brother Leon Brown innocent and ordered them both released from prison.

How would you feel after being on death row while innocent... knowing you were rail-roaded... Would you be thankful to finally be released?Would you be pissed at the injustice?

LUMBERTON, N.C. — Thirty years after their convictions in the rape and murder of an 11-year-old girl in rural North Carolina, based on confessions that they quickly repudiated and said were coerced, two mentally disabled half brothers were declared innocent and ordered released Tuesday by a judge here.

The case against the men, always weak, fell apart after DNA evidence implicated another man whose possible involvement had been somehow overlooked by the authorities even though he lived only a block from where the victim’s body was found, and he had admitted to committing a similar rape and murder at around the same time.

The startling shift in fortunes for the men, Henry Lee McCollum, 50, who has spent three decades on death row, and Leon Brown, 46, who was serving a life sentence, provided one of the most dramatic examples yet of the potential harm from false, coerced confessions and also of the power of DNA tests to exonerate the innocent.

As friends and relatives of the two men wept, a superior court judge in Robeson County, Douglas B. Sasser, said he was vacating their convictions and Mr. McCollum’s death sentence and ordering their release. The courtroom erupted into a standing ovation.

“We waited all these long years for this,” said James McCollum, the father of the man released from death row. “Thank you, Jesus,” he repeated.

The exoneration ends decades of legal and political battles over a case that became notorious in North Carolina and received nationwide discussion, vividly reflecting the country’s fractured views of the death penalty.

The two young defendants were prosecuted by Joe Freeman Britt, the 6-foot-6, Bible-quoting district attorney who was later profiled by “60 Minutes” as the country’s “deadliest D.A.” because he sought the death penalty so often.

For death penalty supporters, the horrifying facts of the girl’s rape and murder only emphasized the justice of applying the ultimate penalty. As recently as 2010, the North Carolina Republican Party put Mr. McCollum’s booking photograph on campaign fliers that accused a Democratic candidate of being soft on crime, according to The News & Observer of Raleigh, N.C.

In 1994, when the United States Supreme Court turned down a request to review the case, Justice Antonin Scalia described Mr. McCollum’s crime as so heinous that it would be hard to argue against lethal injection. But Justice Harry A. Blackmun, in dissent, noted that Mr. McCollum had the mental age of a 9-year-old and that “this factor alone persuades me that the death penalty in this case is unconstitutional.”

The exoneration based on DNA evidence was another example of the way tainted convictions have unraveled in recent years because of new technology and legal defense efforts like those of the Center for Death Penalty Litigation, a nonprofit legal group in North Carolina that took up the case.

In the courtroom here Tuesday, the current district attorney, Johnson Britt (no relation to the original prosecutor), citing his obligation to “seek justice,” not simply gain convictions, said he would not try to reprosecute the men because the state “does not have a case.”

Mr. McCollum was 19 and Mr. Brown was 15 when they were picked up by the police in Red Springs, a town of fewer than 4,000 people in the southern part of the state, on the night of Sept. 28, 1983. The officers were investigating the murder of Sabrina Buie, 11, who had been raped and suffocated with her underwear crammed down her throat, her body left in a soybean field.

No physical evidence tied Mr. McCollum or Mr. Brown, both African-American, as was the victim, to the crime. But a local teenager cast suspicion on Mr. McCollum, who with his half brother had recently moved from New Jersey and was considered an outsider.

After five hours of questioning with no lawyer present and with his mother weeping in the hallway, not allowed to see him, Mr. McCollum told a story of how he and three other youths attacked and killed the girl.

“I had never been under this much pressure, with a person hollering at me and threatening me,” Mr. McCollum said in a recent videotaped interview with The News & Observer. “I just made up a story and gave it to them so they would let me go home.”

After he signed a statement written in longhand by investigators, he asked, “Can I go home now?” according to an account by his defense lawyers.

Before the night was done, Mr. Brown, after being told that his half brother had confessed and facing similar threats that he could be executed if he did not cooperate, also signed a confession. Both men subsequently recanted at trial, saying their confessions had been coerced. The other two men mentioned in Mr. McCollum’s confession were never prosecuted.

Both defendants initially received death sentences for murder. After new trials were ordered by the State Supreme Court, Mr. McCollum was again sentenced to death, while Mr. Brown was convicted only of rape, and his sentence was reduced to life. (In later years, the Supreme Court barred the death penalty for minors and the execution of the mentally disabled.)

Mr. Brown, 46, has been serving a life sentence. Mr. McCollum, 50, has spent three decades on death row. They were expected to be freed on Wednesday. Credit Chuck Liddy/The News & Observer

Lawyers from the Center for Death Penalty Litigation, working with private law firms, began pressing for DNA testing of the physical evidence in the case, which included a cigarette butt found near sticks used in the murder.

Recent DNA testing by an independent state agency, the North Carolina Innocence Inquiry Commission, of evidence gathered in the initial investigation found a match for the DNA on the cigarette butt — not to either of the imprisoned men, but to Roscoe Artis, who lived only a block from where the victim’s body was found and who had a history of convictions for sexual assault.

Only weeks after the murder, in fact, Mr. Artis confessed to the rape and murder of an 18-year-old girl in Red Springs. Mr. Artis received a death sentence, later reduced to life, for that crime and remains in prison. Officials never explained why, despite the remarkable similarities in the crimes, they kept their focus on Mr. McCollum and Mr. Brown even as the men proclaimed their innocence.

The only witness at the hearing Tuesday was Sharon Stellato of the innocence inquiry commission, who under questioning from defense lawyers described the lack of evidence tying the two men to the crime as well as the DNA findings implicating Mr. Artis. The district attorney said he had no evidence to the contrary.

Joe Freeman Britt, the original prosecutor, told The News & Observer last week that he still believed the men were guilty.

After Tuesday’s hearing, Mr. McCollum and Mr. Brown returned to prison to file the paperwork for their release, which to the frustration of defense lawyers and the men’s relatives was delayed, apparently until Wednesday.

As exoneration appeared likely, Mr. McCollum recently reflected on his fate.

“I have never stopped believing that one day I’d be able to walk out that door,” he said in the videotaped interview with The News & Observer.

“A long time ago, I wanted to find me a good wife, I wanted to raise a family, I wanted to have my own business and everything,” he said. “I never got a chance to realize those dreams.

“Now I believe that God is going to bless me to get back out there.”

Correction: September 2, 2014

An earlier version of this article misstated the given name of the Supreme Court justice who noted that Henry Lee McCollum had the mental age of a 9-year-old. It was Justice Harry A. Blackmun, not Hugo.

Jonathan M. Katz reported from Lumberton, and Erik Eckholm from New York.