Donald Trump began his political career by railing against foreigners and migrants, denouncing Mexicans as “rapists” and Muslims as “terrorists” and vowing to "fix" the “broken borders” of the US.

But after two years of Mr Trump's government, with the US facing an unprecedented crisis at its southern border, one might conclude his handling of the issue has been disastrous.

This year the US is on track to receive more than one million migrants, mostly from Central America, a huge number by any standards and far more than the system can cope with. These are largely families with children, surrendering voluntarily to border patrol officers at the earliest opportunity and applying for asylum.

Still, you’d be mistaken to conclude Mr Trump is a complete failure on his signature campaign issue.

To the contrary, his near-singlehanded creation of an undeniably out-of-control predicament isn't the result of incompetence or idiocy, as his detractors suggest.

While Mr Trump simply does not do policy and governance, he is a proven master at demagogic politics.

The US president is, in fact, the primary beneficiary of this chaos, which is why he has worked so hard to create it.

A group of about 30 Brazilian migrants, who had just crossed the US-Mexico border, sit on the ground near border patrol agents. Paul Ratje / AFP

In the 2016 primaries, he stood out from the large pack of credible, mainstream Republicans, mainly because of his hostility to foreigners in general, and migrants in particular.

He was plainly betting that he could win by stoking the racial anxieties of white Americans, given the demographic and cultural transformation of the US which, according to national census predictions, will mean white people will no longer be a majority in the US by 2045 for the first time in the country's history.

Mr Trump attacked immigration to exploit such fears and suggest he would preserve and defend the traditional white, Christian, communal power and privilege that many Americans think is under attack.

He was not subtle about this. And he clearly believes such messaging is primarily how he was able to win the White House, despite losing to Hillary Clinton by nearly three million votes.

Mr Trump didn't bother asking Congress to fund his border wall project when his party controlled the legislature for the first two years of his presidency. As soon as Democrats had the power to block him, the money to fund it suddenly became a pressing issue

After the dreadful drubbing the Republicans took in the midterm elections in November last year, any ideas Mr Trump might have had about running on any other issue in 2020 have clearly been jettisoned.

The tax cuts he secured for the wealthy and corporations were not popular. Healthcare is an utter bust for Republicans. Only a fringe of social conservatives is obsessed with appointing right-wing judges.

His key issue was, and still is, immigration as a proxy for white power.

So the last thing Mr Trump wants is any resolution or even improvement of the immigration issue.

Instead, he is counting on endless, bitter fights about immigration that allow him to pose as the indignant champion of white America, against the treasonous liberals who want to hand the country over to the Mexican “rapists” and Muslim “terrorists” pouring over the border to – as he insists – steal jobs and kill people.

That's why Mr Trump didn't bother asking Congress to fund his border wall project when his party controlled the legislature for the first two years of his presidency. As soon as Democrats had the power to block it, this funding suddenly became a pressing issue, even prompting Mr Trump to impose a lengthy partial federal government shutdown.

Clearly, he doesn't care about actually building a wall or he would have done it when it was relatively easier. What he wants is not a wall but an endless fight about a wall. And he’s got it.

The same goes for curtailing immigration. Many of his pronouncements, such as repeatedly threatening to close the border but not actually doing so, or vowing to tighten criteria for granting asylum, inevitably produce surges of people trying to cross into the US as soon as they can. There is a new rush to get into the US each time he makes such a statement and cynically exacerbates the problem.

This immigration crisis is a self-fulfilling prophecy for Mr Trump. He described a border crisis that didn't exist, enacted measures to ensure one would develop and he is now flailing around with dramatic threats, grand gestures and sound and fury signifying nothing. That is exactly what he wants and why he is carefully avoiding doing anything that might improve the crisis. He has even cut aid to Guatemala, Honduras, and El Salvador, the very countries whose violence and poverty migrants are fleeing in the first place, a move which can only prompt an increase in numbers at the border.

Mr Trump is clearly determined to spend the 18 months before the next election posing as the saviour of white America. The most obvious way he can do that is by stoking fears of migrants, especially given that terrorism in the US is now almost entirely committed by white nationalist extremists.

Expect him to continue exacerbating the immigration crisis while raging against it – and avoiding taking any steps that might ease or resolve it. That's working for him perfectly.

Hussein Ibish is a senior resident scholar at the Arab Gulf States ­Institute in Washington