The gunman behind Austin’s possible terror-related mass shooting entered the US  and cemented his legal immigration status under Democrat administrations — despite a growing criminal record.

Senegalese national Ndiaga Diagne, 53, arrived in America on March 13, 2000, on a B-2 tourist visa during the Clinton administration, a source familiar with his immigration history told The Post on Sunday.

Diagne — who killed two people and wounded 14 more during his rampage outside a Texas bar early Sunday — then became a lawful permanent resident on an IR-6 visa in June 2006 when he married a US citizen, the source said.

Ndiaga Diagne was identified as the gunman who killed two people and injured 14 others during a mass shooting at a bar in Austin, Texas. Obtained by the NY Post

Diagne seen firing into the Buford’s bar in Austin on Sunday morning. X/@WalkerATX

He had already racked up at least one arrest before that, for illegal vending in June 2001 in New York City, law-enforcement sources said.

He then went on to lodge a string of other arrests in the Big Apple between 2008 and 2016 — but that didn’t stop him becoming a naturalized US citizen on April 5, 2013 — around the start of former President Barack Obama’s second term, sources said. Those three arrests are sealed, sources said.

Diagne also was arrested in Texas at some point on undisclosed charges, sources said.

He was a known emotional disturbed person in both states, too, sources said.

Diagne seen wearing a “property of Allah” hoodie and holding a gun at the scene of the shooting. X/@BillMelugin_

Diagne then applied for asylum in 2016, though the outcome or stated purpose of that application was not immediately clear.

The serial offender opened fire outside Buford’s Backyard Beer Garden near the University of Texas-Austin Campus early Sunday, killing two bar patrons and wounding 14 others before he was shot and killed by police.

He was wearing a “Property of Allah” hoodie at the time of the rampage and had a Quran in his car, sources familiar with the investigation told The Post.

The crowded bar seen shortly before the mass shooting. Instagram / Bufords Austin

The FBI is investigating whether he was motivated by the US-Israel-led campaign against Iran — sources said he was wearing an undershirt emblazoned with the Iranian flag or other Iran-related imagery.