For nearly a quarter century, as successive waves of migrants have tried to enter and work in the United States, presidents have appealed to Congress to address gaps in an immigration system nearly everyone agrees is broken.

Yet year after year, congressional efforts to strike a wide-ranging bipartisan deal — one that would strengthen border security measures while expanding avenues for people to immigrate to the United States in an orderly and lawful way — have fractured under the strain of political forces.

Immigration has proved to be a potent political messaging tool, particularly for Republicans, who have rallied voters behind campaigns to close the border with Mexico — and denounced anything other than stringent security proposals as amnesty. And Democrats have long resisted border security initiatives without measures to grant legal status to millions of undocumented immigrants residing in the United States and to expand immigration in the future.

While many lawmakers have tried to bridge the gap, not once in the 21st century has Congress managed to send a comprehensive immigration bill to the president’s desk.

The legacy of that inaction is seen in factories and farms, where undocumented migrants work grueling jobs for low wages; in the skyrocketing backlog of asylum cases that have yet to appear before an immigration judge; in the enrichment of cartels trafficking migrants and drugs to the U.S.-Mexico border; and in the uncertainty at the border after the expiration this week of pandemic-era restrictions on entry.

As lawmakers try to tackle immigration yet again, here is a look at how and why previous efforts in Congress failed.

On May 25, 2006, the Republican-led Senate passed the Comprehensive Immigration Reform Act of 2006 by a vote of 62 to 36. Twenty-three Republicans — including Senator Mitch McConnell of Kentucky, the current minority leader — supported the bill, along with all but four Democrats and one independent. The Republican-led House never took it up.

What was proposed: The bill was based on a compromise struck by Senators John McCain, Republican of Arizona, and Edward M. Kennedy, Democrat of Massachusetts. Their framework coupled border security measures that Republicans were demanding — such as fencing, radar and aerial surveillance tools and an influx of personnel — with provisions championed by Democrats offering millions of undocumented immigrants living in the United States a way to earn citizenship and the creation of a guest worker program.

Why it failed: Despite opposition from some top Republicans, the bill drew enough backing to pass the Senate after an aggressive push by President George W. Bush, who had campaigned on overhauling the immigration system and dedicated a prime-time Oval Office address to promoting the bill the week before the vote. It also had the backing of big business groups and some powerful labor unions.

But the more conservative House, which in late 2005 had passed a bill placing strict limits on immigration and criminalizing unlawful entry — prompting widespread national protests — never took it up, effectively killing it. Republicans instead brought up a measure dealing with only border security, called the Secure Fence Act, which passed both the House and Senate with veto-proof majorities. Mr. Bush signed it into law two weeks before the 2006 midterm elections.

After congressional Republicans suffered punishing defeats in the 2006 midterms, new Democratic majorities in the Senate and House tried to tackle immigration again. But the new bill failed to clear a series of procedural hurdles in the Senate in June 2007 and never received a final vote in either chamber.

What was proposed: The 2007 bill adopted the approach of the previous year’s proposal, but with a “trigger” conditioning legal status for undocumented immigrants on first meeting a series of border security benchmarks. The bill also proposed granting legal status based on a points system that scored immigrants according to job skills, education level, family ties and English-language proficiency.

Why it failed: The coalition of senators that worked out the legislation, which came to be known as the Gang of 12, represented the broadest bipartisan coalition yet to join forces on an immigration compromise. But the bill encountered dogged opposition from both parties and ultimately collapsed.

Senator Jeff Sessions, the Alabama Republican who would go on to carry out a zero-tolerance policy for unlawful border crossings as President Donald J. Trump’s attorney general, led a conservative revolt against the bill, denouncing it as amnesty. At the same time, pro-labor Democrats objected to the expanded temporary guest-worker programs, while others in the party panned the points system for prioritizing job skills over family ties.

In December 2010, Democratic congressional leaders, poised to lose control of the House, held votes on the DREAM Act: legislation that aimed to give undocumented migrants brought to the country as children, often referred to as “Dreamers,” an opportunity to gain legal status. The House passed the bill by a vote of 216 to 198, with eight Republicans in favor and 38 Democrats opposed. Ten days later, the Democrat-led Senate fell five votes short of breaking a filibuster blocking it from a vote.

What was proposed: The legislation sought to enable Dreamers to become legal residents and potentially U.S. citizens, provided they met certain conditions. Eligible migrants would have to have enrolled in college or served in the military for at least two years, pass a criminal-background check and be under 30 years of age. The legislation, first introduced in 2001, had been a component of both the 2006 and 2007 comprehensive immigration bills.

Why it failed: Conservative Republicans in the Senate campaigned against the bill as a grant of amnesty, persuading all but three of their colleagues to oppose it. But Democrats also failed to rally around their party’s legislation. Five moderate Democrats refused to back the bill because it did not include a broader immigration plan — the five votes they needed to clear the Senate’s 60-vote procedural hurdle and allow it to advance.

After the 2012 presidential election and a Republican autopsy that concluded the party had to shift its hard-line stance on immigration, momentum built for a compromise bill. On June 27, 2013, the Senate, voting 68 to 32, passed a compromise immigration bill addressing both border security and expanded immigration pathways, with 14 Republicans on board. But the G.O.P.-led House never acted on it.

What was proposed: A “Gang of Eight” group of senators — four Democrats and four Republicans — revived the idea of pairing border security measures with expanded immigration avenues, subject to meeting trigger thresholds on border security. The bill called for universal adoption of the employment eligibility system, known as E-Verify, to make it more difficult to hire undocumented workers and put most undocumented immigrants in the country on a 13-year pathway to citizenship. It would have awarded visas based on a points system, with about 50 percent based on job skills, and included temporary guest worker programs.

Why it failed: The bill easily passed the Senate but was effectively dead on arrival in the increasingly right-wing House. Speaker John Boehner, Republican of Ohio, repeatedly refused to give it a vote, saying he would not bring up an immigration bill that a majority of Republicans did not support.

After Mr. Trump ended an Obama-era program that extended deportation reprieves and work permits to undocumented immigrants who had been brought to the United States as children, pressure mounted for Congress to codify new protections for them.

But Mr. Trump said any such bill would have to include an end to decades of family-based migration policies, the construction of a border wall and a vast crackdown on other undocumented immigrants. House Republicans tried to pass an immigration overhaul they pitched as a compromise between their own moderates and conservatives. But all House Democrats and about half of House Republicans opposed it, and the measure failed in a 121-to-301 vote on June 27, 2018.

What was proposed: At its core, the Republican bill envisioned authorizing stepped-up border security measures, like Mr. Trump’s wall, alongside measures to give Dreamers a pathway to citizenship. But the legislation also included conservative measures to limit avenues for asylum seekers and criminalize fraudulent claims, as well as make it easier to both detain migrant children and send unaccompanied minors back to their countries of origin.

Why it failed: Faced with a revolt by Republican moderates who had joined forces with Democrats to try to force a vote on legislation to protect the Dreamers, Speaker Paul D. Ryan sought to put forth an overhaul that could please both the conservatives in his ranks and his more mainstream members. But the measure faced brisk headwinds from the start.

Democrats vocally opposed the bill, which Representative Nancy Pelosi of California, then the minority leader, called “a cruel codification of President Trump’s anti-immigrant agenda.” Republicans were still divided. And the legislation lost critical momentum after last-minute waffling by Mr. Trump, who tweeted less than a week before the vote that Republican leaders “should stop wasting their time on immigration” until the party could win more Senate seats.

By the morning of the vote, Mr. Trump was back to championing the legislation, but it was too late to persuade his fractured conference to support it.