WASHINGTON — Shortly before the 2002 midterm elections, Richard A. Gephardt, who was then the House minority leader, infuriated his fellow Democrats when he announced he would help President George W. Bush win authorization for the Iraq war.

“It’s really the most difficult thing you have to ever do — take on a large part of your caucus on something they feel strongly about,” Mr. Gephardt, who represented Missouri, recalled in a recent interview. It is precisely what Speaker John A. Boehner would have to do with his fellow Republicans to move immigration legislation toward a landmark compromise with the Democratic-led Senate and President Obama. And in the unlikely event he tries, Mr. Boehner would face an even more difficult task than Mr. Gephardt.

But treacherous as it would be, the prospect offers Mr. Boehner tantalizing benefits. It could return him and the House to the legislative problem-solving he has long valued but has rarely been able to accomplish as speaker.

It could engrave on his record the adaptation of American law to historical, cultural, demographic and economic changes. It could help his party stem its alienation from the swelling Hispanic electorate and revitalize its ability to win presidential elections. Still, the reasons not to try have hardened into a familiar Washington political consensus.

One view is that trying to move an immigration compromise could cost him his job, perhaps immediately. The House has 233 Republicans, 12 of whom declined to support Mr. Boehner, who represents Ohio, for speaker in January 2013. A few more defections could take away his majority and his gavel.

Another view is that even if Mr. Boehner no longer fears such a rebellion — because, say, he may have decided to retire — his colleagues in the Republican leadership do. Going along with an immigration deal could block their ability to rise.

An additional line of reasoning is that it is unclear if Democrats would agree to any compromise acceptable to a substantial portion of the Tea Party-infused Republican caucus. Representative Eric Cantor of Virginia, the No. 2 Republican in the House who hopes to succeed Mr. Boehner as speaker, has warned against dividing the party before such a promising midterm election for the Republicans. So for now, Mr. Boehner’s charges have focused their energies on invigorating the Republican base with attacks over the Affordable Care Act; the 2012 episode in Benghazi Libya, that killed four Americans; and the I.R.S. over its scrutiny of conservative groups.

Yet Mr. Boehner has not abandoned the idea of a deal because a narrow path for achieving one still exists.

A potential agreement between House Democrats and Republicans starts with the fact that the Senate, with votes from Democrats and one-third of Republicans, has already passed a comprehensive bill. Although Democrats taunt the speaker by challenging him to put the Senate bill on the House floor, no one in Congress actually expects him to, given the views of his caucus.

Unless, that is, he has something to offer. And he does.

“He’s got to have something that has a chance to appeal to a majority of his caucus,” Mr. Gephardt explained. (When he backed Mr. Bush on Iraq, 80 fellow Democrats joined him, while 126 opposed him.)

Image

Richard A. Gephardt, at right in 2002 with President George W. Bush, faced a similar party battle when he helped win authorization for the Iraq war.CreditRon Edmonds/Associated Press

Following a slower, step-by-step immigration approach that Mr. Boehner has advocated, the House Judiciary Committee has cleared several bills on separate aspects of the issue. This summer, after the threat of primary challenges from the right passes for many incumbents, Mr. Boehner has the chance to put one or more of these bills on the floor before lawmakers begin their August recess.

Passage of the bills could then set off months of negotiations for a compromise with the Senate — the very talks that conservatives warn would end with an amnesty deal for the 11 million immigrants here illegally. But Mr. Boehner’s power to appoint House negotiators allows him to shape a more Republican-friendly outcome.

At this point, Mr. Boehner’s task would become more arduous than any he has been willing to shoulder as speaker so far.

First he would have to secure the acquiescence, if not support, of his leadership team in rounding up Republican floor votes. Active opposition from Mr. Cantor, for example, could sink the effort.

Then Mr. Boehner would have to begin intense member-to-member talks to convince colleagues that supporting a deal is the right thing to do. Mr. Gephardt never had to do that on the Iraq vote, which he cast as a life-or-death “conscience vote” for Democrats to decide on their own.

If the potential effort by Mr. Boehner should take place during a postelection, lame-duck session, a White House official estimated that Mr. Boehner would start with perhaps 60 House Republicans willing to back a compromise. Mr. Boehner’s challenge would be swelling that number to about 60 more, or something approaching half the caucus.

Mr. Boehner would have natural allies in business lobbying organizations such as the U.S. Chamber of Commerce, which provides Republicans with crucial financial support. They want Congress to act.

So do some potential 2016 Republican presidential candidates, including Jeb Bush, the former governor of Florida. An immigration deal before the Republican presidential primaries heat up would shrink one big obstacle to their chances in the race.

To most Capitol Hill veterans, this situation sounds fanciful. As speaker, Mr. Boehner has bucked his caucus only when he lacked an alternative. On immigration, inaction offers the path of least resistance.

And the few recent precedents will not encourage him. In 1978, Howard Baker, then the Senate Republican leader, broke with most in his party to help President Jimmy Carter pass the Panama Canal Treaty — only to see his own presidential ambitions fizzle afterward. In 1990, President George Bush bucked rebellious conservatives and raised taxes to reduce the budget deficit, which cost him a second term and earned lasting enmity from the right.

After the Iraq war vote, Mr. Gephardt began an ill-fated 2004 presidential bid. The next year, he called his vote a mistake.

A version of this article appears in print on , on Page A17 of the New York edition with the headline: In a Democrat’s Efforts on Iraq, a Parallel for Boehner on Immigration. Order Reprints | Today’s Paper | Subscribe