Just minutes before the Saturday-morning massacre at a Walmart in the Texas border city of El Paso, a seething, anti-immigrant manifesto appeared on the website 4chan, and by evening investigators were probing if it had been posted by shooting suspect Patrick Crucius.

Authorities had yet to confirm if it had been written by Crucius, El Paso Police Chief Greg Allen told reporters during an evening press conference.

But by early Sunday, investigators were “reasonably confident” that Crusius wrote it, NBC reported.

“Right now we have a manifesto from this individual, that indicates to some degree, it has a nexus to potential hate crime,” Allen said — sounding uncomfortable even speaking about the disturbing document.

The manifesto, titled “The Inconvenient Truth,” starts out proclaiming the author’s support for the March shootings at two mosques in Christchurch, New Zealand.

“This attack,” the author then says, in an apparent reference to his own sick handiwork, “is a response to the Hispanic invasion of Texas.

“They are the instigators, not me,” he rails.

“I am simply defending my country from cultural and ethnic replacement brought on by an invasion,” he wrote.

The Walmart is adjacent to the sprawling Cielo Vista Mall, a popular shopping destination among Mexican tourists.

They cross into the US to shop, then return home with their purchases.

The manifesto bemoans that “America is rotting from the inside out,” and predicts that “the heavy Hispanic population in Texas will make us a Democrat stronghold.”

It goes on to blame immigration for everything from the loss of jobs to runaway pollution.

Then the author writes about his weaponry, griping that he’d rather have used something far more powerful.

“Main gun: AK47,” the author states under the heading, “Gear.”

“I realized pretty quickly that this isn’t a great choice since it’s the civilian version of the ak47,” he complains.

“It’s not designed to shoot rounds quickly,” he says.

“So it overheats massively after about 100 shots fired in quick succession.”

The author goes on to humble-brag about having spent less than a month, “not much time at all,” preparing for the attack.

“I have do this before I lose my nerve,” he wrote.

“I figured that an under-prepared attack and a meh manifesto is better than attack and no manifesto.”

He sees his actions as “faultless,” he adds.

And he’s not a racist, he claims.

“This isn’t an act of imperialism but an act of preservation,” he writes of the ­attack.

“America is full of hypocrites who will blast my actions as the sole result of racism and hatred of other countries, despite the extensive evidence of all the problems these invaders cause and will cause.

Governments kill millions through “imperialistic wars,” he “reasons” — so why shouldn’t he?