Both political parties are in a state of high anxiety about the possibility that President Obama will allow millions of illegal immigrants to remain in the country, fearing that White House action on the issue could change the course of November’s midterm elections.

In the past few days, Democratic candidates in nearly every closely fought Senate race have criticized the idea of aggressive action by Obama. Some strategists say privately that it would signal that he has written off the Democrats’ prospects for retaining control of the chamber, deciding to focus on securing his legacy instead.

Senior Republicans, meanwhile, have their own worries about a “September surprise” on immigration. They know their volatile party’s tendency to erupt at such moments — including government shutdowns and impeachment threats — and that the GOP brand is even more tattered than the Democratic one.

A conservative uprising against the administration would pose little risk for safely entrenched Republicans in the GOP-controlled House. But any move toward impeachment hearings against Obama or another government shutdown would cause serious problems for Republicans in key Senate races. They must appeal to independents who already are suspicious about the party’s ability to govern.

Obama announced in June that he was looking at “additional actions my administration can take on our own, within my existing legal authorities, to do what Congress refuses to do and fix as much of our immigration system as we can.”

The possibilities include not only deferring deportation for millions of illegal immigrants but also providing new green cards for high-tech workers and for the relatives of U.S. citizens and permanent residents, officials say. A decision is expected in coming weeks.

One senior administration official said the White House is balancing various concerns in its deliberations, including the legal limits on the president’s authority, the ongoing child migrant crisis along the Rio Grande River, the communications challenge of explaining the new policy, the impact it is likely to have on Capitol Hill and the implications of acting in the heat of a campaign.

The White House also is feeling pressure from Hispanic groups and other advocates of immigration liberalization, who are weary of being told that they must be patient. On Wednesday, Rep. Luis V. Gutierrez (D-Ill.) met with more than two dozen like-minded activists in the office of Chicago Mayor Rahm Emanuel, who was Obama’s first White House chief of staff.

“We’re preparing and want to make sure it happens,” Gutierrez said. “I’m more optimistic than ever that the president will be broad and generous with his decision.”

He said Obama “is going to determine his legacy with the immigrant community in the next 30 days.”

A dramatic move may well produce long-term political benefits with the nation’s fast-growing Latino electorate. But many of the crucial Senate battles this year are being fought in conservative states with small Latino populations where Obama is unpopular.

Democratic candidates in those states have little appetite for yet another policy battle.

“To me, securing our borders has to be the priority, and that should be the president’s focus,” said Sen. Mark Begich (D-Alaska).

Sen. Kay Hagan (D-N.C.) added, “I am extremely disappointed that the House has stalled on comprehensive immigration reform, but this is an issue that I believe should be addressed legislatively and not through executive order.”

Shripal Shah, an adviser to Sen. Jeanne Shaheen (D-N.H.), said the candidate “believes Congress must address our broken immigration system with a comprehensive fix, and would not support a piecemeal approach issued by executive order.”

Shaheen’s Republican opponent, former Massachusetts senator Scott Brown, is betting that a wave of unrest over immigration could help him win in a state he has only recently called home. His first town hall meeting of the campaign was about “illegal immigration and the ongoing crisis at the border,” and he has produced television ads blasting the “pro-amnesty policies of President Obama and Senator Shaheen.”

At a Kentucky forum last week, Democratic Senate candidate Alison Lundergan Grimes said she is against Obama taking action but added that her opponent, Senate Minority Leader Mitch McConnell (R), is ultimately to blame for opposing reform.

One state where the issue could pay dividends for Democrats this year is Colorado, where 21 percent of the population is Hispanic and Sen. Mark Udall (D) is in a close race against Rep. Cory Gardner (R). Udall has called on Obama to act.

Republicans on Capitol Hill and outside conservative leaders have been watching the White House’s statements. They see an opportunity — but also an opening for the GOP to stumble at a time when the political tide seems to be running in their favor.

“The hope is that he’ll change his mind and won’t take it that far, but it may be a little too late, from what we hear,” said Sen. Jeff Flake (R-Ariz.), who supported the bipartisan immigration bill the Senate passed last year. “Now, we haven’t heard directly from the White House, but if you believe the rumors, there is not much hesitancy.”

Some see the potential for an almost Machiavellian turn of events.

“A cynic would say this is a trap carefully laid by the White House,” said Vin Weber, a well-connected Republican former congressman from Minnesota.

David Winston, a longtime pollster for House Republicans, said: “By doing something like this, the president would incite some Republican members, hoping to change the story line. But whether it changes the story depends on the discipline of the Republican side to make sure that disagreements that exist within the conference do not overwhelm what the conference is trying to achieve overall.”

The two impulses that Republican leaders are eager to tamp down are calls for Obama’s impeachment or another government shutdown.

Rep. Steve King (Iowa), a hard-line tea party conservative, said a shutdown is possible. He has accrued growing influence on the immigration issue this summer, helping to shape the House GOP border security legislation that passed in early August.

King said in an interview that if Obama does move forward with an executive action, many House Republicans will be unwilling to extend funding for the government that is set to expire at the end of September.

“I don’t see how we could reach agreement if he takes that posture,” King said. “It would throw us into a constitutional crisis.”

“No one wants to use the I-word,” King added, when asked about possible calls for impeachment. But he did not rule out the option.

Sen. Marco Rubio (R-Fla.), a potential 2016 presidential candidate, said this week that Republicans may look to connect votes on fiscal and budgetary policy to the immigration issue.

“There will have to be some sort of a budget vote or a continuing resolution vote, so I assume there will be some sort of a vote on this,” Rubio said in an interview with Breitbart, a conservative news Web site. “I’m interested to see what kinds of ideas my colleagues have about using funding mechanisms to address this issue.”

Reining in King and his bloc is likely to be difficult. House Speaker John A. Boehner (R-Ohio) will enter the fall session with an unseasoned leadership team and a long history of strife with the GOP’s tea party caucus.

King said that he and a growing number conservative House Republicans are keeping in touch this summer with a flurry of e-mails and phone calls, readying for whatever may come next month and warning conservative leaders that they need to prepare for a sea change in the midterm dynamics.

“You can expect me to head directly to the nearest airport, get to Washington, and pick up whatever drum I can beat, if the president follows through,” King said. “I’ll call for a special session and ask the leadership to hammer this out on the House floor.”

Top GOP aides on Capitol Hill, who spoke on the condition of anonymity to discuss internal plans, said Republicans’ immediate response would be to play up Obama’s past statements about the limits of his authority to make unilateral changes to immigration policy. They would argue that the president is abusing the power of his office, and then focus on endangered Senate Democrats. Advisers to the National Republican Senatorial Committee already are focused on the idea of Democratic disarray on the issue.

Mitt Romney, the 2012 GOP presidential nominee whose defeat was blamed in part on having alienated Hispanics, said in an interview last week that any short-term political gains made by Obama eventually could be overshadowed by the long-term consequences.

“If the president takes unilateral action and makes law on his own and says he’s going to go around the laws that have been passed by Congress, then he is going to set us back, for who knows how many years, on true immigration reform and the security of our borders,” Romney said. “And that would be a terrible, terrible mistake on his part.”