Representative Mike Lawler, the first-term Republican from a Hudson Valley suburb who is widely considered one of the most politically endangered members of his party, began the week facing brutal attacks from a major House Democratic political group that falsely accused him of trying to force cuts to Medicare and Social Security.

The next day, House Democrats’ campaign arm savaged him as “a rubber stamp for his MAGA colleagues” who is endangering his constituents’ jobs, safety, and health care.

Hours later, Mr. Lawler was sitting in the front row of the audience when President Biden came to his home turf to make Democrats’ case for raising the debt ceiling — and publicly praised him as “not one of these MAGA Republicans.”

Such is life recently for Mr. Lawler, 36, a former state assemblyman who is one of a small group of Republicans representing swing districts who could be crucial to averting a catastrophic default. With the government hurtling toward a debt-ceiling breach that could come as early as June 1, they are now caught in the fray as Mr. Biden and Democrats court them effusively one minute and then pummel them to try to score political points the next.

Mr. Lawler said he attended Mr. Biden’s event this week to show that he was not shrinking from the challenge.

“I’m a big boy — I’m not concerned about what is said by the White House press secretary or the DCCC putting out a statement that clearly was contradicted by the president just a few hours later,” Mr. Lawler said in an interview, referring to House Democrats’ campaign arm. “They’re doing whatever they feel they need to do politically to try and win an election in 2024.” He added that his goal in attending was to make clear his willingness to engage with, listen to, and work with Democrats to resolve the nation’s challenges.

Mr. Biden’s campaign-style rally in the Hudson Valley on Wednesday was intended to ratchet up pressure on Mr. Lawler to break from his party, which has demanded steep spending cuts in exchange for raising the debt limit, and work with Democrats to avert default. It is part of a strategy by Democrats to weaken the negotiating position of Speaker Kevin McCarthy, who must either unite hard-right and more mainstream Republicans on a fiscal deal or risk defections by lawmakers like Mr. Lawler.

Just last week, White House officials were gleefully pummeling Mr. Lawler and the other 17 House Republicans representing districts the president won in 2020, repeatedly posting their names and headshots on Mr. Biden’s official Twitter account and accusing them of advancing an extreme debt ceiling bill that would gut programs that help veterans and older people.

House Majority Forward, a group affiliated with the Democratic Party’s main political action committee for House races, released the results of a poll in which they told respondents that Republicans including Mr. Lawler were “threatening to default on our debt in order to force cuts to Social Security and Medicare.” House Republicans have repeatedly said those programs are off the table in the debt-limit talks, but intentionally did not outline which other programs they would seek to cut, in an effort to avoid accusations that they wanted to gut popular federal services.

Mr. Biden took a different approach, publicly extending an olive branch to Mr. Lawler in a stark contrast with the messaging his party had been blasting out for weeks.

“Mike is the kind of guy that, when I was in the Congress, that’s the kind of Republican I was used to dealing with,” Mr. Biden said. “He’s not one of these MAGA Republicans.”

Speaking directly to Mr. Lawler, Mr. Biden added: “Thanks for coming, Mike. Thanks for being here. This is the way we used to do it.”

As he exited the event, Mr. Lawler saw Karine Jean-Pierre, the White House press secretary, and repeated Mr. Biden’s praise to her, to her apparent amusement.

“Obviously, their social media accounts and official statements should probably better reflect the president’s sentiments and thoughts,” he said later in the interview.

The shout-out — and Mr. Lawler’s decision to attend the event in the first place — underscored the unusual dance playing out just weeks before the nation is at risk of defaulting on its obligations for the first time, with the economy hanging in the balance. White House officials simultaneously are hoping to rally a bloc of moderate Republicans to vote with Democrats to raise the limit — while also gaining a political advantage for the 2024 election by painting them as extremists.

That messaging has infuriated some Biden-district Republicans.

“Think about how asinine this is,” Representative Marc Molinaro of New York, a Republican who represents a neighboring district in the Hudson Valley, said. “You have the president of the United States, who needs members of Congress like myself and others to want to work with him.”

“Instead of negotiating with and including members of Congress,” Mr. Molinaro added, “he’s alienating them.”

Mr. Molinaro said his previous work with White House staff, on supporting mental health and combating substance use, “has been great.” On the debt limit, he said, “the White House should be doing more outreach, and they haven’t.”

But there is a reason Mr. Biden and Democrats may be choosing to target lawmakers like Mr. Molinaro and Mr. Lawler; unlike some of their ultraconservative colleagues from deep-red districts, they know the political risks of being blamed for a default and are determined to avoid them at all costs.

Asked whether he would still be open to working with Democrats to strike a debt limit deal, Mr. Molinaro replied: “At the end of the day, we cannot default on America’s debt. I want Speaker McCarthy to negotiate on our behalf and the president to sit in the White House — not the Hudson Valley — to address this crisis now.”

Republicans like Mr. Lawler are attempting to strike a balance of their own, determined to back their party leaders while also positioning themselves as pragmatic deal-makers who will not tolerate a catastrophic default.

“The objective here is for everybody to negotiate in good faith and find an area of agreement,” Mr. Lawler said in the interview. “None of us are going to get everything we want out of this. We don’t have one-party rule. And so, understanding that and accepting that means that you have to find compromise.”

Mr. Lawler, who met briefly with the president ahead of the rally, said that he wanted Mr. Biden to negotiate in good faith with Mr. McCarthy and a deal that ultimately included spending cuts — and that default was not an option. He said that he believed Democrats and Republicans could find common ground on overhauling permitting regulations for energy projects, tighter work requirements on social programs, and clawing back unspent coronavirus pandemic relief funds.

He declined to say whether he would sign onto a discharge petition in an emergency, to try to force a bill to the floor to avoid a default, saying he wouldn’t discuss hypotheticals. But he added: “Obviously, we cannot default, so we’ll deal with this as it comes.”

In the meantime, similarly situated Republicans have settled in for a season of whiplash.

“They’re Jekyll and Hyde: ‘We want to work with Republicans, but we’re kicking them in the ass in the meantime, at least in the purple districts,’” Representative Don Bacon of Nebraska said of Mr. Biden and Democrats. “Every single one of us in the purple districts know you got to negotiate.”

“Realistically,” he said, “we’ve got to meet in the middle.”