WASHINGTON — Supreme Court Justice Anthony M. Kennedy announced Wednesday that he will retire at the end of next month, preparing the way for the most significant change in the court's makeup in half a century.

The vacancy will allow President Donald Trump to make the Supreme Court a solidly conservative body for years, if not generations, to come — a towering legacy of his time in office.

Trump said Wednesday shortly after Kennedy's announcement that a search for his replacement would begin immediately and he thanked the justice for his service.

A spokesman for Senate Majority Leader Mitch McConnell, R-Ky., said he saw no reason why a new justice couldn't be confirmed before the midterm elections in November. McConnell himself said on the Senate floor that the vote to confirm Kennedy's successor would take place this fall.

When McConnell was asked if he thinks it is fair to hold a confirmation vote on a Supreme Court nominee during an election year after he blocked President Barack Obama's nomination of Merrick Garland during an election year, he responded, "There's no presidential election this year."

Trump has a list of 25 potential Supreme Court nominees that the White House has previously made public and Trump said Kennedy's replacement would come from that list.

"Hopefully we're going to pick someone who will be as outstanding" as Kennedy, Trump told reporters at the White House.

Brett Kavanaugh and Thomas Hardiman are widely believed to be on the president's short list, multiple sources told NBC News. Kavanaugh is a federal appeals court judge in Maryland and a former Kennedy clerk. Hardiman, a Pennsylvania federal judge, was a finalist the last go-round.

Read Kennedy's resignation letter here.

"I’m very honored that he chose to do it during my term in office," Trump said Wednesday night during a campaign appearance in Fargo, North Dakota. "Because he felt confidence in me to make the right choice and carry on his great legacy. That's why he did it."

The president added, "We have a pick to come up, pick a great one, pick one that going to that be there for 40, 45 years."

Vice President Mike Pence tweeted that Trump would nominate a "strong conservative."

Thank you to Justice Anthony Kennedy for your long career of service on the SCOTUS. @POTUS Trump will nominate a strong conservative, in the tradition of the late Justice Scalia, who will uphold all the God-given liberties enshrined in the Constitution of the United States. — Vice President Mike Pence (@VP) June 27, 2018

Kennedy's departure on July 31, which had been rumored for the last year, could put in doubt the future of a nationwide right of access to abortion.

"Justice Kennedy was the most important member of the court in a century, maybe ever," said Tom Goldstein, a Washington lawyer who argues frequently before the court and publishes the SCOTUSblog web site.

Kennedy turns 82 in July and is the court's second-oldest justice. Ruth Bader Ginsburg is 85.

Since 2006, when moderate conservative Sandra Day O'Connor left the court, Kennedy has been the swing justice, often casting the deciding vote in the most high-profile cases.

Joining the court's four other conservatives, he voted to gut the landmark Voting Rights Act, allow corporations and unions to spend unlimited funds to support candidates, and give new life to the Second Amendment right to own a gun.

But he joined the liberals in banning capital punishment for the youngest offenders, declaring that prisoners at Guantánamo Bay had a right to challenge their detentions and limiting the powers of the states to enforce their own tough immigration laws.

Supreme Court Justice Anthony Kennedy gives the thumbs-up after taking the constitutional oath at the White House on Feb. 18, 1988 as President Ronald Reagan looks on. Doug Mills / AP file

He profoundly shaped the court's rulings on gay rights, writing four of its most important decisions, including the landmark 2015 ruling that struck down bans nationwide on same-sex marriage.

"It's not just that he was the pivotal vote so often. It's that his thinking changed the country," Goldstein said. Gay rights is the biggest example, but it's not the only one."

Replacing Kennedy will be the biggest change in the court’s alignment since Earl Warren retired as chief justice in 1969 and was replaced by Warren E. Burger, moving the court decidedly to the right.

Any nominee chosen by Trump is sure to be more conservative than Kennedy. The president is likely to pick someone as ideologically to the right as Neil Gorsuch, who has voted with the court's other conservatives in nearly every case since taking his place on the bench just over a year ago.

President Ronald Reagan nominated Kennedy, a fellow Californian, in 1987 after the Senate rejected Robert Bork as too rigid and after a second nominee, Douglas Ginsburg, admitted smoking marijuana.

At first a reliable conservative, Kennedy soon broke away and voted to uphold the court's 1973 Roe v. Wade abortion decision. But 14 years later, he wrote the ruling that approved a federal ban on so-called partial-birth abortions.

A Trump-nominated successor to Kennedy is likely to become the court's fifth reliable conservative, joining Chief Justice John Roberts and Justices Clarence Thomas, Samuel Alito and Gorsuch. Because only Thomas has declared opposition to Roe v. Wade, it's uncertain whether opponents of abortion would have the five votes needed to overturn it.

At age 69, Kennedy had a stent placed in one of his heart arteries, and underwent the same procedure a year later. But neither kept him off the golf course, and his health has appeared sound.

A year ago, he told friends he was considering stepping down, but he returned to the bench last October for the start of the current term. His departure will end nearly 31 years of service on the Supreme Court.