Dwayne Stafford (Charleston County jail via AP)

In the beginning, it was the most unlikely of friendships.

One was a 25-year-old black man who grew up in foster homes and has been in and out of the South Carolina criminal justice system for years.

His name: Dwayne Stafford.

The other was a 21-year-old Confederate flag-obsessed white supremacist who is accused of gunning down nine black people at Emanuel AME Church in Charleston, S.C.

His name: Dylann Roof.

For a time, at least, the two men — both housed in the Charleston County Detention Center — shared a budding rapport, Stafford told NBC News.

“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 it didn’t take long for the men’s relationship to turn sour. Stafford — who has been accused of robbing someone outside a gas station — told NBC that he decided to attack Roof after Roof talked about his plans to start a race war, a discussion during which Roof insulted Stafford’s father, who had recently died. Stafford said it was at that point that he began plotting his revenge on Roof.

“When he first got there, everyone was cussing him out, saying what they were going to do to him,” Stafford told NBC. “But I wasn’t even in the mind-set 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.”

Several weeks later, NBC reported, Stafford would get his chance. Roof was attacked after he was let out of his cell to take a shower around 7:45 a.m. Aug. 4, Charleston County Sheriff Al Cannon said at a news conference that day.

As Roof left his cell, Stafford “ran down the stairs and was able to get to Roof, who was at or near the shower area,” the sheriff said. Jail officials told NBC that Stafford got out of his cell because guards hadn’t properly locked his door.

“The doors rattle when they lock them,” Stafford told NBC. “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.”

Stafford encountered Roof alone in the shower because one of his guards was on break and the other was running an errand, NBC reported. Stafford told NBC that he first asked Roof a question: “Mind if I join?”

Stafford then began punching Roof “a number of times and assaulted him quickly,” Cannon said. Roof suffered “minor bruising to his face and back area,” the sheriff’s office said in a news release. NBC reported that guards found Roof curled in a fetal position, his body bruised and bloodied.

Stafford and Roof were examined by medical personnel after the incident, which was broken up by a detention deputy.

Asked whether Roof fought back, NBC reported that Stafford laughed. “He tried, but, nah,” Stafford said with a chuckle. “I beat Dylann Roof’s a- -.”

Through his attorney, Roof has informed authorities that he doesn’t want to pursue criminal charges against Stafford, according to the news release.

“Given the circumstances surrounding this incident, an internal investigation and review will be conducted by the Sheriff’s Office, Office of Professional Standards,” the release states.

Stafford is jailed on charges of providing false information to police, strong-armed robbery and first-degree assault and battery, according to online jail records. The Charleston Post and Courier reports that the cases are pending. His bail had been set at $100,000.

Roof is charged in the June 2015 massacre at Emanuel AME Church, which unfolded during a Bible study session at the historic church. Federal prosecutors have said the killings were racially motivated.

Shortly after the attack on Roof, supporters began putting money in Stafford’s commissary account, NBC reported. Marvin Pendarvis — a well-known attorney with a reputation for fighting social justice battles — said he was intent on freeing Stafford from jail. Pendarvis told NBC that a supportive bail bondsman secured Stafford’s release with a deal, freeing the inmate the next day.

“I took my first steps out of jail,” Stafford told NBC, “and I felt secure.”

He has been given temporary housing, money, clothing and food, not to mention a crowdfunding page that aims to pay off his bail bondsmen.

With a single assault, it seems, his life has begun to turn around.

“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.”

MORE READING: 

‘She is my hero’: Mother applauds teenage daughter accused of killing father