The man accused of commandeering a D.C. pizza restaurant with an assault-style rifle anticipated that his efforts could end in violence as he investigated false rumors of a child sex ring, according to court documents made public Tuesday.

New details, including ­allegations that Edgar Maddison Welch tried to recruit two ­co-conspirators, add a chilling twist to the case. Friends and family members had earlier said they thought the 28-year-old North Carolina man was on a mission to save children, not to hurt anybody.

Prosecutors wrote in a criminal complaint that “it appears Welch had been contemplating a violent confrontation at the restaurant.” They outlined various text messages he sent in the days before the Dec. 4 incident at Comet Ping Pong.

“Raiding a pedo ring, possible [sic] sacrificing the lives of a few for the lives of many,” Welch texted a friend two days before he drove to Washington in a Toyota Prius, according to federal prosecutors. The text continued: “Standing up against a corrupt system that kidnaps, tortures and rapes ­babies and children in our own backyard.”

Police said Welch was ­consumed with the viral fake news story, known as “Pizzagate,” that falsely linked Hillary ­Clinton to a child sex-trafficking ring. The conspiracy theory said the ring operated in the basement of Comet, where Clinton’s presidential campaign chairman, John Podesta, occasionally dined.

Comet Ping Pong customers came out to support the restaurant after a gunman entered it with an assault rifle, firing it at least once. Several other businesses on the block have received other threats as well. (Whitney Shefte/The Washington Post)

In the end, Welch did not shoot anyone and surrendered after he found no evidence of hidden rooms or sex trafficking, police said. The documents state that adults and children were in the restaurant that Sunday afternoon and fled when the gunman walked inside with a .38-caliber Colt revolver and a Colt AR-15 rifle — loaded with 23 bullets — strapped across his chest.

Welch fired his assault-style weapon two or three times in the restaurant, police said. They said he also pointed the rifle in the direction of an employee who had emerged from the back with pizza dough after everyone else had fled.

The information detailing Welch’s apparent planning is contained in court documents filed Tuesday as Welch’s criminal case was moved from D.C. Superior Court to U.S. District Court, in the federal system.

At a brief federal court hearing Tuesday afternoon, Welch appeared in an orange jail jumpsuit with a trimmed goatee beard and close-cropped blond hair, ­apparently cut since his arrest. He said little other than to request a federal public defender, explaining that he had no job and less than $100.

U.S. Magistrate Judge G. Michael Harvey set a hearing for Friday to decide whether Welch should remain in jail, at which time he could enter a plea.

In an interview Monday, Welch’s parents, Harry Welch Jr. and Terri Welch, said they did not know of their son’s interest in the fake news story or his apparent plan to investigate it. “We were stunned,” Terri Welch said. She apologized “for any heartaches he has caused.”

Prosecutors lost a bid to have Welch’s criminal complaint sealed for a brief time. They had argued that making it public could give people Welch texted an opportunity to destroy electronic evidence, dodge investigators or conspire to develop a consistent story.

“The sealing for a very limited time is necessary because the statement of facts contains very sensitive information, the disclosure of which would not be in the interest of the government, the public, and a pending ongoing investigation,” Assistant U.S. Attorney Demian S. Ahn wrote in a request filed Monday.

Welch is charged with carrying a firearm across state lines with intent to commit a crime, which carries a maximum sentence of 10 years in prison. Police said he also carried a folding knife and had a loaded shotgun in the Prius. His cellphone was found in the vehicle.

The criminal complaint says Welch had grown increasingly angry about reports he read online about the supposed sex ring. On Dec. 1, the complaint says, Welch texted his girlfriend and said that he was researching “Pizzagate” and that what he read made him “sick.” He also looked up Comet Ping Pong on the Internet.

That night, the complaint says, Welch texted another friend about his plans. That friend asked Welch whether they were going to “save the Indians from the pipeline,” a reference to protests in North Dakota by the Standing Rock Sioux Reservation over plans to build an oil pipeline near their land.

Welch responded that he had something “way more important” with “much higher stakes” planned, and mentioned “Pizzagate.” The friend responded, “Sounds like we r freeing some oppressed pizza from the hands of an evil pizza joint.” Later, authorities wrote, that friend texted Welch, “I’m in.”

The next day, Dec. 2, ­prosecutors said, Welch asked whether his friend knew anyone from the Army who could help. The friend responded “that it depended on the cause,” the court document says.

According to the complaint, Welch texted back and said he was “defending the next generation of kids, our kids, from ever having to experience this kind of evil themselves. . . . The world is too afraid to act and I’m too stubborn not to.”

Authorities said Welch left his home town of Salisbury, N.C., the morning of Dec. 4. It’s unclear why he didn’t connect with his other friends; one texted him to meet, the complaint says, but Welch responded that he was already on his way.

At some point, he recorded a video that was found on his phone. The complaint says Welch looks into the camera and tells relatives that he loves them, that he hoped he had “showed it,” and “that he hoped that he would be able to tell them again. And if not, don’t ever forget it.” As he drove, he texted his girlfriend that he “might be gone awhile.”

About 3 p.m., authorities said, Welch parked near Comet, on Connecticut Avenue in upper Northwest, and walked in with the assault-style rifle and went to the back. The complaint says he did not interfere with customers and employees as they ran out.

While inside, and as the police massed outside, Welch searched for hidden rooms or tunnels, the complaint says. ­Encountering a locked door, he tried to open it with a butter knife, and then tried to shoot off the lock with his assault rifle. That didn’t work, and ­prosecutors said he climbed on top of furniture to look over a partition. The room was empty.

Michael E. Miller, Dana Hedgpeth and Susan Svrluga contributed to this report.