A shooting in Texas which has left 20 people dead is being investigated as a possible hate crime, officials have said.

Police have arrested 21-year-old Patrick Crusius following the shooting at a Walmart supermarket in the city of El Paso, near the US-Mexico border, on Saturday.

A further 26 people were injured in the attack.

Officials have not offered a precise motive for the attack, but El Paso Police Chief Greg Allen said investigators were looking into a document that could indicate a "potential nexus to a hate crime".

The document, apparently posted online shortly before the attack, espoused white supremacist and racist views and claimed the shooting was a response to "the Hispanic invasion of Texas".

It also expresses support for the gunman who killed 51 people in Christchurch, New Zealand, in March.

Although a Twitter account that appears to belong to Mr Crusius included pro-Trump posts praising the plan to build more border wall, the writer of the online document says his views on race pre-dated Mr Trump’s campaign and that any attempt to blame the president for his actions was “fake news”.

Reacting to the two shootings online, President Donald Trump tweeted: "God bless the people of El Paso Texas. God bless the people of Dayton, Ohio."

He added that the FBI, local and state law enforcement were working together to investigate both attacks.

Police said the Texas suspect, who surrendered after being confronted by officers outside the store, was still being interviewed.

"We're going to aggressively prosecute it both as capital murder but also as a hate crime, which is exactly what it appears to be," Texas Governor Greg Abbott told reporters.

READ MORE: Suspect dead as three killed in shooting at food festival in Gilroy, California 

The store was packed with as many as 3,000 people during the busy back-to-school shopping season.

“The scene was a horrific one,” said El Paso Police Chief Greg Allen, who added that many of the wounded had life-threatening injuries.

In the hours after the shooting, authorities blocked streets near a home in Allen, Dallas, associated with the suspect.

Officers appeared to speak briefly with a woman who answered the door of the grey stone house and later entered the residence.

Texas Mall ShootingA vigil for victims is held in El Paso, Texas (AP Photo/John Locher)

Following the shooting, residents volunteered to give blood to the injured, while police and military members were trying to help people who were looking for missing loved ones.

READ MORE: One dead, 11 injured in Brooklyn shooting 

“It’s chaos right now,” said Austin Johnson, an Army medic at nearby Fort Bliss, who volunteered to help at the shopping centre and later at the school that was serving as a reunification centre.

Adriana Quezada, 39, said she was in the women’s clothing section of Walmart with her two children when the shooting happened.

“I heard the shots but I thought they were hits, like roof construction,” she said.

Her 19-year-old daughter and 16-year-old son threw themselves to the ground, then ran out of the Walmart through an emergency exit. They were not hurt, Ms Quezada said.

The suspect, who used a rifle, was arrested without incident. Police believe he was the sole gunman but are continuing to investigate reports that others were involved.

The mass shooting in El Paso came less than a week after a gunman opened fire on a California food festival.

Santino William Legan, 19, killed three people and injured 13 others last Sunday at the popular Gilroy Garlic Festival, and died of a self-inflicted gunshot wound.

Ryan Mielke, a spokesman for University Medical Centre of El Paso, said 12 people were brought to the hospital with injuries, including one who died.

Two of the injured were children who were being transferred to El Paso Children’s Hospital, he said. He declined to provide additional details on the victims.

Eleven other victims were being treated at Del Sol Medical Centre, according to hospital spokesman Victor Guerrero. He said those victims’ ages ranged from 35 to 82.

Texas governor Greg Abbott called the shooting “a heinous and senseless act of violence” and said the state had deployed a number of law enforcement officers to the city.

“Reports are very bad, many killed,” US president Donald Trump tweeted.

Presidential candidate and former Texas congressman Beto O’Rourke appeared a bit shaken as he appeared at a candidate forum in Las Vegas, shortly after news of the shooting in his hometown was reported.

Mr O’Rourke, who said he had called his wife before going on stage, said the shooting shattered “any illusion that we have that progress is inevitable” on tackling gun violence.

El Paso, which has about 680,000 residents, is in West Texas and sits across the border from Juarez, Mexico.

The city has become a focal point of the immigration debates.

This is the 21st mass killing in the United States in 2019, and the fifth public mass shooting. Before today, 96 people had died in mass killings in 2019 — 26 of them in public mass shootings.