It was a long and tough fight that will probably stand as President Barack Obama’s most glaring failure of his two-term presidency.
Last week, a tie vote by the Supreme Court thwarted the president's last change to shield up to 4 million people from deportation. He was forced to give his version of concession speech on a fight that has frustrated him like few others.
Despite two campaigns full of promises, Obama leaves behind an outdated and overwhelmed system, with some 11 million people living in the U.S. illegally. He will be remembered for protecting 730,000 young people, a generation of so-called Dreamers, who were brought to the U.S. as children.
Advocates and allies will credit him with embracing a newly aggressive assertion of executive power that, despite the court deadlock and political opposition, remains a legal pathway for the next president. And he will go down as a leader who consistently defended the importance of immigrants in American life, as anti-immigrant sentiment swelled up in parts of the U.S. and abroad.
"Immigration is not something to fear," Obama said last week. "We don't have to wall ourselves off from those who may not look like us right now or pray like we do, or have a different last name."
"What makes us Americans," he proclaimed, "is our shared commitment to an ideal that all of us are created equal, all of us have a chance to make of our lives what we will."
But Obama also will be remembered as a president who prioritized other issues, missing perhaps the best chance to pass sweeping legislation and only reluctantly adjusting his strategy in the face of firm opposition.
And his administration aggressively enforced current laws, deporting more than 2.4 million people. The total is nearly as many as his two predecessors combined.
"His strategy early on was to prove his enforcement bona fides," said Janet Murguia, president of the National Council of La Raza, an immigration advocacy group, who once labeled Obama the "deporter-in-chief."
"He was facing an unprecedented, highly personalized opposition from Congress," she said. "We fault him, I believe correctly, for failing to recognize soon enough this intransigence by Congress and failing to use his authority sooner."
If evaluating Obama's record is a matter of tallying two columns — in one, the number of people he protected from removal; in the other, the number deported — the Supreme Court went a long way last week toward tipping the ledger toward the latter.
The decision left in place an injunction freezing his 2014 executive action, which expanded his protection of Dreamers and temporarily protected some parents of people with legal status.
The deadlock, resulting from a Republican blockade against Obama's Supreme Court nominee, left the constitutionality of the action unsettled. But it had a significant impact on Obama's legacy.
"If the Supreme Court had ruled in his favor, he'd probably be remembered as the person who helped to protect half of the undocumented population in the country, which probably would have been a turning point toward reform sooner rather than later," said Frank Sharry, founder of the immigration reform group America's Voice. Instead, he said Obama will be most remembered for his administration's "record number of deportations."
The White House rejects a by-the-numbers analysis. Work to modernize the border and bring new order to a chaotic deportation system isn't necessarily conveyed in the calculation, officials argue.
The administration overhauled the role of local law enforcement. In 2014, the president declared the administration's limited resources would be focused on removing threats to national security and public safety and recent arrivals. Deportation has decreased since. Last year, the administration deported the fewest people since 2006.
"Devising that approach and implementing it has fundamentally changed the way laws are enforced and has had a real impact on communities," said Cecilia Munoz, the president's chief adviser on immigration. "That's a very, very big change. That's a large piece of the legacy."
It is a piece of the legacy that remains controversial. Prioritizing recent arrivals inevitably means targeting some of the women and children who have been fleeing violence in Central America. A series of Christmastime raids last year revived complaints about the policy from Democrats and immigrant advocates. The White House has shown no sign of backing down.
Could Obama have charted a different course on immigration?
Entering office during an economic crisis, Obama focused on stimulating growth and reforming the financial sector. Then there was his massive health care legislation. Along the way, he broke a campaign promise to back overhaul legislation on immigration in his first year.
It was 2011 before Obama endorsed a set of reform principles. By then, Democrats had lost control of the House and the best window for passing a bill had closed.
With Latinos, a key political constituency, restless ahead of his re-election bid, Obama announced his first executive action to shield Dreamers in June 2012. He made a new law a top priority of his second term. Although the Senate passed legislation, the GOP-led House refused to vote on it.
"Republicans never gave him credit for the actions that were taken both in terms of security on the border and deportations that did occur," said Sen. Jeff Flake, a Republican from Arizona who backed the Senate bill but opposed Obama's executive actions. "It was a more robust program than Republicans ever gave him credit for. But no good deed goes unpunished in this political environment. The narrative was kind of set and it was furthered by the actions that he took."
After claiming he did not have the authority, Obama bowed to intense pressure from advocates and announced a second executive action in November 2014. He'd waited until after midterm elections, concerned he would damage prospects for senators in tough races. Democrats lost the Senate anyway and the move revived Republican charges of unconstitutional overreach. More than two dozen states eventually signed on to a court challenge that froze the program.
Still, allies cast Obama's about-face as a game-changer. Future presidents almost certainly will try to flex similar authority to work around gridlock on Capitol Hill. Hillary Clinton, the presumptive Democratic nominee, has promised to go further than Obama.
"He has rewritten the playbook and added several pages to it on what the executive can and should do. There's a lot of room there," said Angela Kelley, an immigration expert at the Center for America Progress. "Is that necessarily the best way? No. But it is legal, and it is smart and strategic."
Whether the courts agree will help shape Obama's legacy.
Resolution isn't likely until after he leaves office.
Clinton would likely pick up where Obama left off in pushing to address the status of the millions of immigrants living in the U.S. illegally.
If Republican Donald Trump prevails, Obama's effort could end up as another painful, close-but-not-quite moment. Trump has proposed building a wall along the border with Mexico and barring Muslims from the U.S.
"The finish line has been in sight for a very, very long time," said Munoz, a veteran of legislative battles over immigration. "It is only a matter of political will."
Based on reporting by the Associated Press.