About 20 minutes before the shooting started at a Walmart in El Paso, Texas, a rant was posted to an online message board saying the massacre was in response to an "invasion" of Hispanics coming across the US southern border.
Subscribe now for unlimited access.
$0/
(min cost $0)
or signup to continue reading
Titled The Inconvenient Truth, it railed against the dangers of mass immigration and warned that Hispanics will eventually take over the economy and government.
The writer argued that attacking "low-security" targets was a way to "fight to reclaim my country from destruction".
Investigators increasingly believe these are the words of 21-year-old Patrick Crusius, who surrendered shortly after Saturday's rampage.
They are looking closely at the writing as they prepare to prosecute the slaughter of 20 people and the wounding of 26 more as a hate crime.
"We have to attribute that manifesto directly to him (Crusius)," El Paso police chief Greg Allen told reporters on Sunday.
"And so we're going down that road."
What remains a mystery is why Crusius chose El Paso, which has figured prominently in the immigration debate, and a shopping complex just 8km from the US-Mexico border.
The scene was a 10-hour drive and a world away from the life he lived growing up in a leafy, upper-middle-class suburb of Dallas.
Security video showed a skinny young man marching through the front door of the Walmart in a black T-shirt and khaki pants, carrying an AK-47 military-style rifle with an extended capacity magazine.
Witnesses say he went aisle by aisle through a store packed with people stocking up on back-to-school supplies.
The dead included at least three Mexican citizens and a 25-year-old mother of three who was shot while holding her two-month-old baby.
The first sentence of the online rant posted on the 8chan message board expressed support for the man accused of killing 51 people at two New Zealand mosques in March.
The online rant speaks of a "Hispanic invasion of Texas".
"They are the instigators, not me," it says.
"I am simply defending my country from cultural and ethnic replacement brought on by an invasion."
A Twitter account that appears to belong to Crusius included pro-Trump posts praising the plan to build a border wall.
However the writer of the online document says his views on race pre-dated Donald Trump's campaign and that any attempt to blame the president for his actions was "fake news".
Some of the language included in the document echoed Trump's own words, characterising Hispanic migrants as invaders taking American jobs and arguing to "send them back".
Though the writer denied he was a white supremacist, the document says "race mixing" is destroying the nation and recommends dividing the US into territorial enclaves determined by race.
The writer went on to say he has an AK-47-style semi-automatic rifle and coolly debates the positives and negatives of using that firearm rather than another military-style weapon, the AR-15, for killing as many people as possible.
Australian Associated Press