Federal authorities have busted a South Carolina man with white supremacist links for attempting to buy a gun in order to carry out a massacre at a synagogue “in the spirit of Dylann Roof,” according to federal court papers.

Benjamin Thomas Samuel McDowell, 29, was nabbed Wednesday after buying the .40-caliber Glock for $109 from an undercover FBI agent, the federal court complaint says.

McDowell agreed to meet with the agent under the pretense the undercover was someone who “handled problems for the Aryan Nations,” the papers read.

The self-proclaimed “white warrior” also attempted to smoke weed after meeting the undercover in a hotel room, but respected the agent’s wishes that he didn’t, while nervously stating he “did not want to get caught and go back to jail.”

McDowell also groused that other white supremacists weren’t devoted enough to the cause, complaining that standing around shouting “white power” was ineffective.

“I got the heart to do that s–t,” he told the undercover, “but I don’t have the good training.”

The purported white nationalist — who has prison tattoos connecting him to the group and is not allowed a gun because he’s a convicted felon — had hinted he planned to attack the Myrtle Beach, SC Temple Emanu-El Synagogue on Facebook, according to an affidavit accompanying the complaint.

In a Jan. 5, anti-Semitic ode to the convicted murderer, McDowell appeared to blame Jews across the world for diluting the white bloodline and incapacitating his white supremacist brethren with drugs.

“All they wanne [sic] do is stay loaded on drugs the Jews put here to destroy white man and they feast on the drugs,” he wrote. “They should be Feasting on the enemy that stole their Heritage and their bloodline and [are] trying to run us off of this Earth.”

“If you ain’t got the heart to fight for Yahweh like dylann roof did you need to shut the f******up,” the troubling post concludes.

McDowell told the agent he wanted “do something on a f—ing big scale” and intended to scrawl a message on the temple’s wall reading, “In the spirit of Dylann Roof,” following his attack, the papers say.

Roof is the white supremacist sentenced to death for the 2015 murder of nine parishioners at a historic black church in Charleston, South Carolina.

McDowell was charged Thursday with felony weapons possession.

He was held without bail Thursday, and will return to court Feb. 21.