Dwayne Stafford was likely on his way to being just another throw away, a product of South Carolina’s notoriously deficient foster care system that churns out troubled children like a meat grinder.

Between the ages of 3 and 18 he’d cycled through more than a dozen foster homes. He fought with family and neighbors and struggled with the trauma of instability. At 21, he started to rack up summonses, arrests and jail time. At 25 he’s facing strong armed robbery and assault and battery charges for a crime he says he didn’t commit.RELATED: Admitted Emanuel AME shooter Dylann Roof attacked in jail shower

According to Stafford’s lawyer, Stafford is accused of roughing up and robbing someone outside of a gas station he frequented. No one was seriously hurt, but the incident landed Stafford in the county jail, where he served 571 days while awaiting trial before finally being bonded out earlier this month.

RELATED: Man who assaulted admitted Charleston Church Shooter Dylann Roof released from jail

But despite his rocky, winding path through the foster care and criminal justice systems, Stafford sees a bit of hope on the horizon, thanks to a twist of fate and a jailhouse fight with a mass-murderer.

If Stafford’s name doesn’t ring a bell, he’s the black guy who snuck out of his cell last week and beat up a fellow inmate, Dylann Roof, the 21-year-old white supremacist charged with killing nine parishioners at the historic Emanuel A.M.E. Church in Charleston, South Carolina.

“I wouldn’t say it’s justice, but I felt as if I did the right thing,” Stafford said in an interview on Friday, his first with national news media.

From the moment Roof stepped onto the unit, a “special management unit” reserved for inmates who might have problems in general population, Stafford was drawn to the scraggly killer.

“When he first got there, everyone was cussing him out, saying what they were going to do to him,” Stafford said. “But I wasn’t even in the mindset of violence. I was more like damn, that could’ve been my people. No, they were my people. I just didn’t understand how he could do that… Pure evil.”

Still, Stafford said that he’d engage in small talk with Roof. He said he’d walk by his cell and they’d chat about politics and current events, sometimes girls.

“I’d say, ‘What’s up man,’ and he’d come to the cell door smiling like I’m his friend,” Stafford said. “But the whole time I’m looking at him like, you couldn’t find nothing else to do with your life? I didn’t know I was going to get him but it was more of a ‘you know what you did’ type thing.”

But soon enough, Stafford said he knew he had to do something. He said that one day not too long ago he’d pressed Roof on his plans to start a race war, and at some point Roof insulted Stafford’s recently-deceased father.

From that moment on, Stafford fumed. No more small talk. No more faux friendship. Weeks passed. Then in a stroke of serendipity, there was an opening. A pair of prison guards responsible for guarding the unit botched the jail’s inmate handling procedure.

It was Thursday, Aug. 4, a little after 7 a.m. Jail officials say that when guards locked down the unit in order to take Roof to the showers they failed to properly lock Stafford’s cell door.

“The doors rattle when they lock them,” Stafford said. “My door didn’t rattle. He didn’t pull it hard enough. After I heard all the other doors rattle, I pushed on the door and went downstairs.”

There, Stafford found Roof alone in the shower. One of the officers had gone on break and the other was delivering toilet paper to another inmate, according to officials.

Stafford said he uttered just four words before he started throwing punches: “Mind if I join?”

By the time jail guards responded Roof was badly bloodied, curled up in a fetal position.

Did Roof fight back?

“He tried, but, nah,” Stafford said with a chuckle. “I beat Dylann Roof’s ass.”

Charleston County Sherriff Al Cannon Jr., who runs the jail, blamed the incident on “complacency” and at the time told reporters that it was not clear if race was a factor, “beyond the obvious speculation that we would all have given the nature of the situation.”

News of the jailhouse beat down quickly went viral, with social media users cheering Stafford on.

Community activists began calling the jail inquiring about Stafford’s bond, which was set at $100,000 for the robbery and assault charges. Other supporters began to rally together to see how they could help, while good Samaritans added a few hundred dollars on his jail commissary.

Within hours, community organizers reached out to attorney Marvin Pendarvis, who soon joined the team as Stafford’s lawyer. Pendarvis, who has made a name for himself as a fierce advocate for the poor and vulnerable, said he was going to do everything he could to get Stafford out of jail.

Despite rumors that supporters sent hundreds of thousands of dollars to pay Stafford’s bond, Pendarvis said a well-meaning bail bondsman cut a favorable deal to secure his release.

Stafford was out the following day.

“I took my first steps out of jail,” he said, “and I felt secure.”

It was a feeling he said he’s rarely felt. He was homeless when he went into jail. He didn’t have much clothing and very little money. But he emerged from jail something of a folk hero. People have given him temporary housing and have donated money, clothing and food.

His supporters have also set up a crowdfunding page to collect donations to pay off the money owed to the bail bondsmen, and to support him until he goes to trial on his earlier charges. Stafford said he was innocent of those charges and that “they got the wrong guy.”

For Stafford, the long road to redemption wound its way through foster care, jail, and ultimately through Dylann Roof, who has declined to press charges. Stafford said that he hopes to stay out of jail, to help others and to use his voice for those who don’t have one. And that he’s thankful for his turn of good luck, after a life filled with the opposite.

“I respect people, especially when they say I don’t condone violence but you did the right thing,” Stafford said. “I just look straight up at the sky and thank Jesus because that could’ve gone really wrong.”