EL PASO, Texas — The man accused of carrying out last weekend’s deadly mass shooting at Walmart in the Texas border city of El Paso confessed to officers while he was surrendering and later explained that he had been targeting Mexicans.

Patrick Crusius, 21, emerged with his hands up from a vehicle that was stopped at an intersection shortly after last Saturday’s attack and told officers, “I’m the shooter,” Detective Adrian Garcia said in an arrest warrant affidavit.

Crusius later waived his Miranda Rights and agreed to speak with detectives, telling them that he had driven to El Paso from the Dallas suburb of Allen — which is where he lived and is a more than 10-hour drive from El Paso — and that he was targeting Mexicans in the attack.

Twenty-two people were killed and about two dozen others were wounded in the attack. Many of the dead had Latino last names and eight of them were Mexican nationals.

Authorities believe Crusius posted a racist online screed that railed against an influx of Hispanics into the U.S. shortly before the attack.

Crusius has been charged with capital murder and is being held without bond. Federal prosecutors have said they are also considering hate-crime charges.

Hours after the attack in El Paso, a gunman killed nine people and wounded many others in Dayton, Ohio.

El Paso sits on the border with Mexico and has a large Latino population.