By Lawrence Hurley

WASHINGTON (Reuters) - The U.S. Supreme Court on Thursday blocked President Barack Obama's plan to spare millions of immigrants in the country illegally from deportation in a split ruling that heartened political foes who had accused him of overstepping his powers.

The 4-4 ruling, coming seven months before Obama's term in office ends, marked the latest success that his Republican adversaries have had in thwarting a major policy initiative of the Democratic president. Obama had hoped that overhauling the U.S. immigration system and resolving the fate of the estimated 11 million people in the country illegally would be part of his presidential legacy.

The ruling is likely to further amplify the role that the immigration issue will play in the run-up to the Nov. 8 presidential election in which voters will pick Obama's successor. It also leaves in legal limbo the roughly 4 million people Obama's action was meant to help.

Obama unveiled his plan in November 2014. It was quickly challenged in court by Republican-governed Texas and 25 other states that argued that Obama overstepped the powers granted to him by the U.S. Constitution by infringing upon the authority of Congress. His unilateral executive action bypassed the Republican-led Congress.

Because the court was split, a 2015 lower-court ruling invalidating Obama's plan was left in place. The plan never was implemented because the lower courts had blocked it.

The plan was tailored to let roughly 4 million people - those who have lived illegally in the United States at least since 2010, have no criminal record and have children who are U.S. citizens or lawful permanent residents - get into a program that shields them from deportation and supplies work permits.

A split ruling was possible because the court was down to eight justices, four liberals and four conservatives, after conservative justice Antonin Scalia died in February. The Republican-led Senate has refused to act on Obama's nomination of appeals court judge Merrick Garland to replace Scalia.

In an appearance at the White House after the ruling, Obama expressed frustration at the court's inability to issue a decisive ruling on the merits of the case and at Senate Republicans for "willfully" keeping the court shorthanded.

"I think it is heartbreaking for the millions of immigrants who made their lives here, who've raised families here, who hope for the opportunity to work, pay taxes, serve in our military, and fully contribute to this country we all love in an open way," Obama said.

Obama said the U.S. immigration system has been broken for two decades and that this ruling set it back even further.

The issue of illegal immigration has featured prominently in the presidential campaign. Donald Trump, the presumptive Republican nominee, has called for deportation of all illegal immigrants - most of them from Mexico and other Latin American countries - and building a wall along the Mexican border.

The court did not reveal how each justice voted in the ruling, but it was possible the four liberals backed Obama and the four conservatives backed the states.

    The court appeared divided along ideological lines during oral arguments on April 18, with liberals indicating support for the administration and conservative opposed.

'MAJOR SETBACK'

The nation's top elected Republican, U.S. House of Representatives Speaker Paul Ryan, and others in his party welcomed the ruling.

"This is a major setback to President Obama’s attempts to expand executive power, and a victory for those who believe in the separation of powers and the rule of law," said Texas Attorney General Ken Paxton, a Republican.

The Constitution assigns certain powers to the executive, legislative and judicial branches of the federal government.

The split decision set no nationwide legal precedent on presidential power or immigration law. The ruling indicates that any major immigration policy change that would address the long-term situation of illegal immigrants would have to be enacted by Congress.

"We feel that justice has turned its back on millions of immigrants who, much like our founding fathers and mothers, sought a better future for themselves and their children and yet continue to live in the shadows without the respect and dignity that they deserve," said Jorge-Mario Cabrera, a spokesman for the Coalition for Humane Immigrant Rights of Los Angeles.

The Obama administration could ask the high court to rehear the case, as losing parties in two other cases in which the court has split 4-4 have done. The court has not yet acted on those other petitions.

The Supreme Court decision does not affect a separate 2012 program aimed at protecting people brought to the United States as children from deportation, which Texas and the other states did not challenge.

Obama took the action after House Republicans killed bipartisan immigration legislation, billed as the biggest overhaul of U.S. laws on the matter in decades and providing a path to citizenship for illegal immigrants, that was passed by the Senate in 2013.

Maya Ledezma, an immigrant from Mexico who lives in Maryland, said would have been eligible for Obama's program because she has lived in the United States for more than a decade and has an 8-year-old daughter who is a U.S. citizen.

“My life would have changed if the vote had been favorable,” she said through a translator during a rally outside the Supreme Court.

Republicans have been critical of Obama's use of executive action to get around Congress on immigration policy and other issues such as gun control and healthcare.

Presumptive Democratic presidential nominee Hillary Clinton criticized the ruling for "throwing millions of families across our country into a state of uncertainty." Trump said the ruling "blocked one of the most unconstitutional actions ever undertaken by a president."

(Additional reporting by Ayesha Rascoe and Emily Stephenson in Washington and Alex Dobuzinskis in Los Angeles)