US President Donald Trump vetoed a measure to terminate his emergency declaration to fund a border wall, striking back at Republican and Democratic lawmakers who opposed the controversial move with the first veto of his presidency.

While Congress is unlikely to muster the votes to override the veto, the rebuke from some members of his own party left Mr Trump politically wounded, at least temporarily, as immigration and his planned wall along the US southern border become a flash point again in the 2020 presidential campaign.

The bipartisan vote in the Senate yesterday approving the measure was a slap to Mr Trump over his decision to circumvent Congress and take money already designated for other programmes to pay for a barrier along the US-Mexico border.

Twelve of Mr Trump's fellow Republicans joined Democrats to pass the measure to end the emergency declaration.

Mr Trump called the resolution reckless and said he was proud to veto it.

"As president, the protection of the nation is my highest duty. Yesterday, Congress passed a dangerous resolution that if signed into law would put countless Americans in danger, very grave danger," he said, sitting behind his desk in the Oval Office.

"Congress has the freedom to pass this resolution, and I have the duty to veto it."

Mr Trump expressed pride in the Republicans who did not vote to support the resolution and said later that he had sympathy for those who defied him, adding they did what they had to do.

The White House had lobbied heavily for Republicans to back Mr Trump, despite concerns among some about executive overreach and precedent-setting action that a future Democratic president could copy on policies that Republicans oppose.

US Attorney General William Barr said the action the president had taken was legal.

The emergency declaration is being challenged in court as an unconstitutional usurpation of Congress' power of the purse.

Mr Trump was flanked by border officials and people whose family members were killed by someone who was in the United States illegally.

The president has said he wants a wall to prevent immigrants from crossing into the United States illegally.

Democrats deny there is an emergency at the border, saying border crossings are at a four-decade low.