US President Donald Trump has said the search for a replacement for retiring Supreme Court Justice Anthony Kennedy will "begin immediately".

"We have to pick one that's going to be there for 40 years, 45 years," Mr Trump said at a rally in North Dakota.

The retirement of Mr Kennedy, a conservative who sided with liberals on many votes, gives Mr Trump the chance to shift the balance of the top court further to the right for decades to come.

The judge, 81, will retire on 31 July.

He made the announcement on Wednesday, saying he wanted to spend more time with his family after 30 years on the top court. Mr Trump later praised Mr Kennedy - who held the pivotal vote on many key cases - as "a great justice of the Supreme Court".

"Hopefully we are going to pick somebody who will be as outstanding," he told reporters at the White House. The judge's retirement gives Mr Trump his second Supreme Court pick since he became president, and he has said he will choose from a list of 25 conservative candidates.

The Supreme Court plays a key role in American life and is often the final word on highly contentious laws, disputes between states and the federal government, and final appeals to stay executions.

This week the court upheld Mr Trump's travel ban which covers people from several Muslim-majority countries, in a 5-4 conservative majority ruling. Earlier this month it ruled in favour of a baker in Colorado who refused to make a wedding cake for a gay couple.

Speaking at the rally in Fargo, North Dakota on Wednesday evening, President Trump told supporters that Mr Kennedy had chosen to retire under his presidency "because he felt confident in me to make the right choice and carry on his great legacy".

The president has promised to draw names from the same list from which he picked Neil Gorsuch in February last year.

Mr Kennedy, who is the second-oldest justice on the nine-member US Supreme Court, earned a reputation as a swing vote conservative who supported liberal arguments on key decisions, including the 5-4 rulings that decided same-sex marriage and upheld abortion rights.

As a result, news of his retirement has raised fears among pro-choice groups that access to legal abortions in several states could be under threat.

Mr Trump, during his presidential campaign, vowed to attempt to overturn Roe v Wade, the 1973 decision legalising abortion throughout the US.

"If we put another two or perhaps three justices on, that is really what will happen. That will happen automatically in my opinion. Because I am putting pro-life justices on the court," Mr Trump said during an October 2016 debate with Hillary Clinton.

Senate Majority Leader Mitch McConnell, a Republican, said on Wednesday that a vote on Mr Trump's nominee to replace Mr Kennedy would take place by the autumn.

The Senate is currently controlled by the Republicans but that could change after mid-term elections in November.

Top Democrat Chuck Schumer said in a televised speech on the floor of the Senate that Mr Kennedy's replacement would be a decision affecting "generations" and therefore the confirmation vote should not take place until after the mid-terms.

"Our Republican colleagues in the Senate should follow the rule they set in 2016, not to consider a Supreme Court Justice in an election year," Senator Schumer said, referring to the blocking of President Obama's nominee Merrick Garland by the Republican Senate majority.

"Anything but that would be the absolute height of hypocrisy."

Who is Anthony Kennedy?
Mr Kennedy, who was raised in California, was nominated by President Ronald Reagan and began his term in 1988.

He voted conservative on issues of campaign finance, voting rights and gun rights.

Mr Kennedy penned the Supreme Court's first major gay-rights decision in 1996, protecting LGBT Americans from discrimination.

In 2015, he authored the landmark opinion which gave LGBT citizens the right to marry, writing: "They ask for equal dignity in the eyes of the law and the Constitution grants them that right."

As a justice, he routinely favoured personal liberty and the limiting of federal power.

Mr Trump said Mr Kennedy had "displayed great vision" and "tremendous heart".

The White House also released a statement thanking Mr Kennedy for his 30 years of service as a "tireless voice for individual rights".

"His words have left an indelible mark not only on this generation, but on the fabric of American history."