Image copyright Reuters Image caption Donald Trump says a wall is needed to keep illegal migrants and criminals out of the US

A US judge once singled out by President Donald Trump over his Mexican ancestry has thrown out a legal bid to stop controversial plans for a border wall with Mexico.

Environmental groups and the state of California complained that the proposed wall violated environmental laws.

They were challenging waivers granted by the Department of Homeland Security.

But Judge Gonzalo Curiel rejected the lawsuit, saying the government was not exceeding its legal authority.

During his presidential campaign, Mr Trump had suggested Judge Curiel's "Mexican heritage" might make him biased in a separate case.

The legal challenge to the wall - a key election pledge by President Trump - was filed in a San Diego federal court and asked for construction to be blocked until the government demonstrated compliance with environmental laws.

Judge Curiel rejected the lawsuit, adding that "the court cannot and does not consider whether underlying decisions to construct the border barriers are politically wise or prudent".

Image copyright Reuters Image caption A section of border fence in Calexico, California, is being replaced by a new "wall"

The ruling was welcomed by the US Department of Justice.

"Border security is paramount to stemming the flow of illegal immigration that contributes to rising violent crime and to the drug crisis, and undermines national security," spokesman Devin O'Malley said.

However, Brian Segee, a senior lawyer at the Center for Biological Diversity, said they intended to appeal against the "disappointing ruling".

"The Trump administration has completely overreached its authority in its rush to build this destructive, senseless wall," he said.

"They're giving unprecedented, sweeping power to an unelected agency chief to ignore dozens of laws and crash through hundreds of miles of spectacular borderlands. This is unconstitutional and shouldn't be allowed to stand."

Californian Attorney General Xavier Becerra accused the Trump administration of "ignoring laws it doesn't like in order to resuscitate a campaign talking point of building a wall on our southern border".

The border wall with Mexico was one of Mr Trump's most controversial election pledges.

Although a popular project with many of his supporters, it aroused widespread anger, not least in Mexico itself.

Judge Curiel, who was born in the US state of Indiana, oversaw a lawsuit in 2016 involving Trump University but Mr Trump hit out at him, alleging that his Mexican ancestry might sway his decision.

Eight prototypes for the wall were completed in San Diego in October and construction has already begun on a 30ft- (9.m) high barrier in Calexico, California.