WASHINGTON — President Donald Trump went after Rep. Beto O'Rourke, D-Texas, who is challenging Republican Sen. Ted Cruz in a closely watched re-election campaign, at a Houston rally for the incumbent Monday night.

"Ted's opponent in this race is a stone-cold phony named Robert Francis O'Rourke, sometimes referred to as 'Beto,'" Trump told the crowd, mocking the Democrat's nickname, which he has gone by since childhood. "He pretends to be a moderate, but he's actually a radical, open borders left-winger."

Trump took advantage of his proximity to the U.S.-Mexico border and hit hard on immigration.

He accused O'Rourke and Democrats of opposing a wall, supporting sanctuary cities, backing "open borders" and favoring amnesty for undocumented immigrants.

The president also touched on the caravan of thousands of migrants that has made its way through Central America over the past few weeks toward the Texas border.

"I think the Democrats had something to do with it," Trump said, although there's no evidence to support the claim, as NBC News has reported. "That's an assault on our country."

The crowd of thousands chanted "Build the wall! Build the wall" in response.

Trump again warned that "illegal aliens" are voting in elections and called for tougher voter ID laws, although widespread voter fraud has not been found in any recent election.

The president also offered effusive praise for Cruz, his former foe, who is in a closer-than-expected re-election battle against O'Rourke. The Real Clear Politics average of polls finds Cruz leading by 7 percentage points.

"I will tell you what, nobody has helped me more with your tax cuts, with your regulations, with all of the things that we are doing, including military and our vets, than Senator Ted Cruz. Nobody," Trump said.

Trump's warm comments are a far cry from the 2016 primary campaign, when the two presidential candidates attacked each other in the most personal ways. Trump nicknamed Cruz "lyin' Ted," implied without evidence that Cruz's father was involved in the assassination of President John F. Kennedy and ridiculed Cruz's wife, Heidi, for her appearance.

At the time, Cruz called Trump a "sniveling coward" and a "pathological liar." He also refused to endorse Trump at the Republican convention.

That was all forgotten Monday.

"He's not lying Ted anymore. He's beautiful Ted," Trump told reporters in an about-face on the White House South Lawn before his departure to Houston.

Cruz addressed the Houston crowd Monday night before the president took the stage and said, "God bless Donald Trump!"

Cruz pivoted to his own re-election race, framing the choice between him and O'Rourke as jobs versus mobs, evoking one of Trump's favorite campaign slogans.

"Do we defend freedom or give into tyranny? Do we embrace jobs or give into mobs?"

O'Rourke has captured national Democrats' attention with his boyish charm and Kennedy-esque looks. He's stunned political operatives on both sides of the aisles by raking in over $38 million in campaign donations in the most recent fundraising quarter.

O’Rourke's political rise has been likened to that of Barack Obama, who ran for president and won after serving less than two years in the Senate.

"If Beto pulls off beating Cruz, he would become a national Democrat immediately," said James Henson, the director of the Texas Politics Project at the University of Texas at Austin. "He would enter the 2020 conversation."

As for the bad blood between Trump and Cruz, Henson says there is good reason for Trump to put that aside.

"Texas is important to the Electoral College and the Republican universe," Henson said. "If there is any sign of Texas becoming more competitive, then I think a Republican presidential candidate has a lot of incentive to come and make sure things are shored up here."

Former Trump campaign adviser Michael Caputo said Trump was there Monday night to thank Cruz.

"In a world where a few more delicate GOP primary opponents are still continuously chafed by 2016, Senator Cruz has become a friend," Caputo told NBC News in an email. "That kind of man — who rises above and seeks true partnership — will always have his friendship reciprocated by this president."