He spent two years planning.

He wrote a rambling, racist 16,500-word screed stuffed with memes, poems and video game references.

Then Brenton Tarrant allegedly stormed two New Zealand mosques and slaughtered worshippers with an assault weapon scrawled with white supremacist slogans — while broadcasting the whole horrifying attack to world.

The man charged with murder for the terrorist attack that killed 49 people in Christchurch was revealed on Friday as a 28-year-old former personal trainer who left his small hometown in Australia eight years ago to travel the world.

But instead of becoming a global citizen, he transformed into a hate-fueled monster, steeped in the language of online trolls and hellbent on mass murder to prevent what he called “white genocide.”

In a 74-page manifesto posted to the vitriolic online message board 8chan just before he began livestreaming the massacre, Tarrant outlined the evil ideology behind his bloody rampage — saying it was “revenge” for Islamic terror attacks and was intended “to create an atmosphere of fear and change in which drastic, powerful and revolutionary action can occur.”

He also said he hoped his assault would spark a civil war in the United States.

“This conflict over the 2nd amendment and the attempted removal of firearms rights will ultimately result in a civil war that will eventually balkanize the US along political, cultural and, most importantly, racial lines,” Tarrant wrote.

“This balkanization of the US will not only result in the racial separation of the people within the United States ensuring the future of the White race on the North American continent, but also ensuring the death of the ‘melting pot’ pipe dream.”

Tarrant came from the small city of Grafton in northern New South Wales, where he had worked as a personal trainer at a gym before spending the bulk of his 20s traveling around the world.

Locals told The Australian newspaper that Tarrant came from a “beautiful family” but that his dad died in 2010, leaving an inheritance that he seems to have used to fund his globetrotting.

“Recently came into contact with a bit of capital due to the passing away of my father,” Tarrant wrote on an online forum about stocks in 2011.

“Really don’t want to lose the money as he paid for it with 30+ years of his life.”

But other online posts at the time struck a very different tone. He said he wanted to spend time “playing video games, snorting coke and hiring strippers” and bragged about being “the strongest person [pound for pound] in my town,” according to The Australian.

Still, those who knew him claim the man on the shocking livestream wasn’t the one who left Grafton eight years ago.

“I think something’s really happened in this person’s travels … He never showed any extremist tendencies in conversations I had with him,” Tracey Gray, who owns the gym where he once worked, told The Sydney Morning Herald.

‘Somewhere along the lines, experiences or a group have got a hold of him.’

“Somewhere along the lines, experiences or a group have got a hold of him.”

Tarrant himself claims in his manifesto that he began to “change” while traveling Europe in 2017, when a terrorist killed five people in a Stockholm truck attack

“Something that had been a part of my life for as long as I could remember, cynicism in the face of attacks on the West by islamic invaders, was suddenly no longer there,” he wrote.

“I could no longer bring the sneer to my face, I could no longer turn my back on the violence.”

He said he spent two years plotting his own rampage, with three months focused specifically on the city of Christchurch.

He originally came to New Zealand to “live temporarily” while he “planned and trained,” but ended up deciding to stage the mass shooting there to show “that no where in the world was safe.”

“The invaders were in all of our lands, even in the remotest areas of the world and that there was no where left to go that was safe and free from mass immigration,” he wrote.

He at first planned on attacking a mosque in the New Zealand city of Dunedin, where authorities say he had been living, but instead selected the Al Noor and Linwood mosques in Christchurch because they were more “optically foreign building[s].”

Tarrant said he also planned a third assault on a mosque in the town of Ashburton, which he described as a “bonus objective” that he wasn’t sure he would reach.

The manifesto is titled “The Great Replacement” in an apparent reference to a right-wing conspiracy theory that white Europeans are being replaced by non-white immigrants.

It is peppered with poems from Keats and Kipling and online in-jokes.

It isn’t clear what is serious and what is sarcastic.

In one section, he claims the person who influenced him “above all” was the African-American conservative commentator Candace Owens.

“Though I will have to disavow some of her beliefs, the extreme actions she calls for are too much, even for my tastes,” he writes.

In another, he sarcastically claims that the children’s video game “Spyro the Dragon 3” taught him “ethno-nationalism” while “Fortnite” “trained me to be a killer and to floss on the corpses of my enemies” — an apparent reference to dance moves in the cartoon-like shooting game.

Tarrant then undercuts that claim in the next line, writing a simple “No.”

Ben Nimmo, a fellow at the Atlantic Council’s Digital Forensic Research Lab, told The Guardian that Tarrant’s words reflect an “online culture where everything can be a joke and extremist content can be a parody and deadly serious all on the same page.”

“You have these communities who routinely practice extreme rhetoric as a joke, so it’s very easy to fit in if you’re a real extremist,” he said.

Tarrant’s sick livestream was also laced with historical and internet references.

Music heard playing as he drives to the first mosque is a song glorifying Bosnian Serb political leader Radovan Karadzic, who was jailed in 2008 for genocide and other war crimes against Bosnian Muslims.

At another point, Tarrant urges viewers to “subscribe to PewDiePie,” a Swedish YouTube star whose real name is Felix Kjellberg. Kjellberg said on Friday that he was “absolutely sickened having my name uttered by this person.”

Words scrawled on Tarrant’s rifles and ammo magazines included references to Ebba Akerlund — an 11-year-old girl killed in the Stockholm attack — the names of 15th-century Hungarian military leaders, as well as the number 14, possibly for the “14 words” of a white supremacist slogan derived from Adolf Hitler’s “Mein Kampf.”

Tarrant appeared in a Christchurch court to face murder charges on Saturday. Courtroom photos released to the media show him cuffed and wearing jail clothing but with his face blurred out.

Still, Tarrant is seen forming a circle with his thumb and forefinger — appearing to flash a “white power” gesture popular online.

With Wire Services