The Allan B Polunsky Unit is a maximum security prison in Polk County, Texas, an hour or so north of Houston.

To get there from the freeway, you take Farm To Market 350, a road lined with trailer parks, bungalows and barns in varying states of disrepair. The nearest Baptist church is a spire bolted to a corrugated steel container. An ornament on a farm gate, shaped like a gun, warns: "We don't call 911."

For the past 12 years, Larry Swearingen, who is 41, has been living in solitary confinement in an 8ft by 12ft cell, with a slit of natural light by the ceiling, too narrow to be called a window. He has a toilet, a typewriter, a radio and a hotplate. His daily hour of recreation and exercise is spent alone, although he can talk and play chess through gaps between the cells.

He is strikingly calm, his voice rarely rising, even as he talks about being locked up for a murder that forensic science shows he cannot have committed. "It's not easy being here," he says. "There are men who are hanging themselves, men who are cutting themselves, men sitting in their own faeces, men slowly losing their minds."

The Texas Department of Criminal Justice website has pen portraits of the 291 men and nine women incarcerated here. Most have committed horrific acts of violence, often against society's most vulnerable: children, the elderly, the disabled and defenceless. Many have been here for years, some even for decades, gradually exhausting their appeals and awaiting execution.

"You have to accept what's coming and go through it," says Swearingen, who will be executed by lethal injection if and when his appeals run out. "There are some guys that I've been around that can't do it. One guy thought he could teleport out of here, that if he stayed awake for long enough he could escape his body and not suffer."

Swearingen sometimes lapses into platitudes, about faith, forgiveness and cherishing the simple things. I wonder whether this is an act, or a result of his prolonged isolation, with only his thoughts and prayers for company.

To supporters of the death penalty, the possibility of a fatal miscarriage of justice is negligible. Conservative Supreme Court Justice Antonin Scalia has said there has not been "a single case in which it is clear a person was executed for a crime he did not commit."

Swearingen's appeal lawyer, Steve Jackson, offers a scathing rejoinder. "There is no way that statement is credible," he says. "We see faulty testimony, the arrogance of the state, not turning over favourable information to the defence, incompetent attorneys who are not qualified to handle these types of cases. To say no-one's been executed wrongfully is not only a mis-statement, it's an absolute lie."

In Texas, doubts have been raised by the case of Todd Willingham, who was executed in 2004 after being found guilty of starting the fire that killed his three young children, a conviction secured with misleading forensic reports, unreliable eyewitness statements, the word of a jailhouse informant and testimony from a psychiatrist who pronounced Willingham a "sociopath" without having met him. Several renowned arson investigators have since concluded the fire almost certainly started accidentally.

Professor James Liebman at Columbia University recently published a book about the wrongful execution of Carlos DeLuna. Another man, Carlos Hernandez, later confessed to the 1983 stabbing of Wanda Lopez. Hernandez carried a knife and had a history of violence against women. He also left plenty of evidence at the scene of the murder, including a bloody footprint, but police, having arrested DeLuna, never even considered him a suspect.

Last year, Troy Davis was executed in Georgia after a federal court upheld his conviction for shooting a police officer, Mark McPhail, even though no forensic evidence was presented at his trial and several of the eyewitnesses who testified against him changed their stories. The case provoked an international outcry, but it is no more possible to prove Davis's innocence than it is to be certain of his guilt.

Swearingen's case is different, in that science provides him with an alibi. He cannot have kidnapped, raped and murdered his supposed victim, because he was already in prison when she was killed. If his last appeal fails and he is executed, abolitionists will have the unequivocal miscarriage of justice they have been waiting for.

Melissa Trotter disappeared on December 8, 1998. Swearingen was one of the last people seen with her – he says they were having a relationship. He was arrested three days later and treated as the only suspect. It was another three weeks before Trotter's body was found in a remote forest clearing where there are known to be vultures, wild pigs and other predators. A search team with cadaver dogs had passed close by a fortnight earlier and found nothing.

Although there were signs of decomposition around Trotter's head, her corpse was in remarkably good condition. Her heart, lungs and spleen were whole. Neither her brain nor her pancreas had liquefied. To judge by the condition of her organs, preserved in histology slides, she had been dead for less than a week. The pathologist who conducted the autopsy, Harris County Medical Examiner Joye Carter, assessed the post-mortem interval based on the external condition of the body alone, with the district attorney and two of his sheriffs in the room. Her official estimate of "25 days or so" was just long enough for Swearingen to be the killer.

In his brief to the court, the director of the Laboratory of Forensic Anthropology, Harrell Gill-King, noted that "seven different forensic experts have now told the judicial system that Mr Swearingen could not have committed this crime".

It would not be the first egregious miscarriage of justice in Montgomery County. In 1981, a school janitor, Clarence Brandley, was jailed for murdering a teenage volleyball player, despite another man's blood and pubic hair being found on her body. Setting him free, after nine years on death row, District Judge Perry Picket wrote that "no case has presented a more shocking scenario of the effects of racial prejudice, perjured testimony, witness intimidation and an investigation the outcome of which was predetermined".

In 2000, Governor George W Bush pardoned Roy Criner, who had spent a decade behind bars for aggravated sexual assault. The appeals court repeatedly turned down Criner's appeals, even after genetic testing proved sperm recovered from the victim did not belong to him.

Swearingen has had three execution dates, stayed each time by the Texas Court of Criminal Appeals. Prosecutors are pressing for a fourth and the judge has yet to announce his ruling. Warren Diepraam, the assistant district attorney of Montgomery County, is the state's lead attorney. "From a prosecutorial perspective – and obviously the jury and the judge and the appellate courts have agreed – there is overwhelming evidence of guilt," he says. "We want to make sure we are convinced not beyond a reasonable doubt but beyond a shadow of a doubt. I think what is happening is that the scientists on the defence side have gone from being neutral observers to advocates on behalf of Mr Swearingen." If the Texas appeals court upholds the conviction, Swearingen has run out of options. The decision will be made shortly.

The court, composed of nine elected judges, has only ordered three retrials of capital cases in the past decade. An "actual innocence" petition to the Supreme Court has been denied. Any further appeals will be summarily rejected. Barring an unprecedented last-minute pardon, Swearingen will be taken to the execution chamber at Huntsville and strapped to a stretcher and injected with sodium thiobarbital to anaesthetise him, pancurium bromide to paralyse his muscles and potassium chloride to stop his heart. He could be executed by the end of this year, although 2013 looks more likely.

Only eight people were sentenced to death last year in Texas, compared with 48 in 1999. This can be attributed to the new sentence of life without parole, available to juries since 2005, but it also speaks to a collective awareness of the fallibility of justice. "There are cases where science has brought forth questions about the validity of the conviction," Diepraam says. "Now we have certain types of DNA that are highly discriminating, people are being freed from prison – and I think that plays a role in the public's psyche about the death penalty. We can always let somebody out of prison if they are wrongfully convicted, but once somebody is executed, that's irreversible."

Anthony Graves knows how long it can take for an injustice to be rectified. He spent 18 years in prison, 14 of them on death row, after being found guilty of murdering a grandmother, her daughter and four of her grandchildren. His execution date was set twice, but he never stopped protesting his innocence. "When you lose hope, you lose your mind," he says, "because the reality sinks in that you're just gonna be here like an animal until you're murdered."

The Texas appeals court repeatedly upheld his conviction but after a retrial new prosecutors admitted there was no evidence linking him to the crime and set him free. Graves has been out for two years. He is trying to build a relationship with his three sons, who are now grown men. He cries when he thinks about calling his mother the day he was released, but he is upbeat. "I don't have time for being angry and bitter," he says. "It has no place in what I want to accomplish."

His case illustrates how easily an innocent man can become trapped in a system that provides a political incentive for prosecutors to seek and judges to uphold death sentences. His conviction was based almost entirely on the word of the actual killer, Robert Carter, propped up by the lies of jailhouse informants and forensic guesswork presented as fact, but because his original defence and first appeal were poorly handled, his appellate lawyers were severely const-rained in the evidence they could present.

Carter retracted his testimony to whoever would listen, in letters from jail and on his death bed – his last words before he was executed were: "It was me and me alone. Anthony Graves had nothing to do with it. I lied on him in court." But the district attorney successfully fought to have his statements ruled inadmissible. Only a prosecutorial slip, admitting that Carter had changed his story in a TV news feature about the case, saved Graves from being sent to his death.

"'Innocent until proven guilty are words written on a piece of paper," Graves says. "That's not how our system functions. A prosecutor can attempt murder on a man's life and get away with it."

As district attorneys and judges are elected officials, they are reluctant to admit prosecutorial misconduct or judicial error.

"Nobody wants to be seen as soft on crime," says Swearingen. "My trial judge is up for re-election and he's very public about how he's never had a death penalty case overturned in his court."

Poor defendants in Texas generally get a court-appointed lawyer for their trial and initial appeal. An investigation found that of the 131 people executed under Governor Bush, 43 were represented by attorneys who had been disbarred or suspended for unprofessional conduct. Texas has since passed the Fair Defence Act, in response to the notorious case of a lawyer who went to sleep at his client's trial, but defence teams still often lack the experience and resources they need.

"I'm not a staunch opponent of the death penalty," says Swearingen's lawyer Steve Jackson. "I think the system works to an extent. The problem is we don't properly fund defence attorneys. We have to scratch and claw for experts. I have over $10,000 of my own money in this case and may never get reimbursed."

Only certain types of murder qualify as capital crimes: when the victim is a child or a police officer, for instance, or when the killing is combined with another felony, such as rape or armed robbery. Hundreds of people are on death row for stick-ups gone wrong – crimes of poverty, addiction or desperation – one more reason capital punishment is disproportionately reserved for the poor. Black and Hispanic defendants are also much more likely to receive a death sentence, particularly if their victim is white.

"The African-American population is about 11-12% and they constitute about 45% of death row and 45% of executions in the modern era. That should strike us as very troubling, and it does," says Professor Robert Blecker of New York Law School. As a high-profile supporter of the death penalty, he believes the system of defining and trying capital crimes should be reformed.

"It's not an all-or-nothing decision," he says. "This is the appropriate occasion to study it, revise it and refine it. Don't abolish it or [refuse to change it]. Both of those decisions are wrong. It is sometimes the only appropriate response to certain horrific murders, but let's be more precise."

Since the turn of the millennium, more than 50 men have been freed from death row in the United States after having their convictions overturned. There are signs that this steady drip of exonerations is beginning to erode faith in the death penalty. Illinois abolished capital punishment last year. The governor of Oregon, John Kitzhaber, halted a pending execution and declared that no more would occur during his tenure.

In the most recent Gallup poll about attitudes to the death penalty, 61% of respondents said they support capital punishment. When offered the alternative of sentencing criminals to life without parole, in a CNN survey, there was a more even split, 50% to 48% in favour of incarceration. "The truth is that even in the face of this abolitionist drumbeat, to shame us out of supporting the death penalty and to overemphasise the remote possibility of executing an innocent person, support is remarkably resilient," says Blecker.

Critics of capital punishment hope a proven miscarriage of justice will have a similar effect on public opinion as the 10 Rillington Place tragedy in Britain, in which Timothy Evans was wrongly convicted of killing his wife, and hanged, only for John Christie to confess to the murder, along with several others. Evans was posthumously pardoned and the death penalty suspended. "It's gonna end," says Graves. "It's like with slavery, segregation, nobody thought it was gonna end. But it ended. And this too shall come to pass." He argues that the death penalty, with its drawn-out appeals process, constitutes "cruel and unusual punishment", and thus violates the Eighth Amendment to the US Constitution. "From the seats I sat in for 18 years, seeing men going crazy, losing their minds, because they're sitting in a cell with no windows, no television, no telephone, waiting to be executed. That's torture. I'd rather you put your hands on me, because those wounds will heal," he says.

Under the current Supreme Court, among the most conservative ever, a national moratorium remains a remote prospect. Jackson, a veteran criminal defence lawyer, has seen many scandalous judicial violations flare up, but fail to influence the debate. "You're talking about a society in Texas that I don't think really cares," he says.

Swearingen is optimistic that he will be granted a reversal. But he also knows there is a chance he will be executed and become a martyr to a cause that is not of his choosing. "I hope it saves people's lives," he says. "The more and more people released from prison over DNA, people are starting to look at it now – would you want to sit on a jury and sentence a person to death, not knowing what evidence is being kept from you?" n