Mr. Roof’s choice to represent himself in the penalty phase of his trial, and to reject a defense based on mental incapacity, has raised questions about his desire to avoid execution. But in the aftermath of the attack, at least, he saw a continued purpose for his life.

“I want to live now,” he wrote in the journal, most of which was read from the witness stand by a Charleston County Sheriff’s Office official, Lauren M. Knapp. “I want to see a future. I want to help make the way.”

He began by explaining that he wanted to complete the rambling racist thoughts included in an online manifesto that he began before the massacre, which he said he “was unable to finish before because I was in a hurry to get to Charleston.”

In a dizzying blitz of insults and stereotypes, predictions and perceived problems, Mr. Roof railed against Jews, Hispanics, African-Americans, gays and Muslims. He said that Adolf Hitler would someday “be inducted as a saint,” and he warned that unless white people “take violent action, we have no future.”

Prosecutors used the writings, which were confiscated by jail officials on Aug. 3, 2015, to bolster their contention that he had opened fire with “substantial planning and premeditation,” which the authorities argue is an aggravating factor in Mr. Roof’s capital case.