HAGERSTOWN, Md. — To keep the base happy, a group of governors has defended the federal health care law, signed new gun control legislation and stood up to President Trump when his words or policies aggrieved them. All are Republican.

In a year when congressional Republicans are clinging to the president like tomato vines to a trellis, Republican governors running for re-election in the heavily Democratic states of Maryland, Massachusetts, Vermont and, to a lesser degree, Illinois have emerged as well-positioned incumbents who seem likely to survive an expected blue swell in November.

A crucial mix of bipartisanship, aggressively mild temperaments and gentle checks on liberal proclivities have kept moderates and independents happy in their states.

“My answer to anybody who doesn’t like the direction our Republican Party is going is to elect good Republicans,” said Jud Ashman, the Democratic mayor of Gaithersburg, Md., in the deep blue suburbs of Washington, who supports the state’s Republican governor, Larry Hogan. “I may be the only elected Democrat who will endorse him, but I won’t be the only one to vote for him.”

As governor, Mr. Hogan has promoted environmental protections for the Chesapeake Bay, shored up the state’s insurance markets and openly fought his own cancer as he worked. He recently pulled back his state’s National Guard troops from the southern United States border in protest of the administration’s policy of separating migrant children from their families. He lowered bridge tolls and some taxes that pleased voters in his heavily taxed state. Almost half of his cabinet members are Democrats.

“I always did exactly what I said I’m going to do,” Mr. Hogan said in a recent interview here, hiding from rain under the slats of an opioid treatment center under construction. “On every issue, I’ve never said, ‘What’s the Republican answer? What’s the Democratic answer?’ I listen to both sides. I don’t care whose idea it is.”

Many current and former elected Democrats in the state have shied from endorsing his opponent, Ben Jealous, a former head of the N.A.A.C.P. “Larry Hogan is just fine on all my core issues,” Mr. Ashman said. “He is pro-choice, pro-marriage equality, pro-gun safety and has excelled at improving the business climate in the state.”

There are 36 governorships in play this fall, many with Republicans on the defensive. The ones in Florida, Maine, Michigan, Nevada, New Mexico and Ohio — all currently held by retiring Republicans — are rated tossups or worse for the party.

Image

Gov. Larry Hogan of Maryland, a Republican, was an early rejecter of President Trump when he was campaigning in 2016.CreditAlex Wroblewski for The New York Times

In a year that is expected to draw far more Democratic voters to the polls than the typical midterm election, Republicans in blue states will depend on the Democrats who helped them win in the first place, and who might be tempted to split their tickets this time. To woo them, most have signed on to policies that appeal to those voters.

While criticizing the president can be a political death sentence for many Republicans, it is more of a life raft for governors in these states. Mr. Hogan was an early rejecter of Mr. Trump, and Mr. Scott and Mr. Baker have openly criticized the president’s policies. All are rated safe or nearly so by political strategists who study governors’ races.

“Three of the five most popular governors are Republicans in blue states,” said Jennifer E. Duffy, senior editor for The Cook Political Report, an independent newsletter in Washington. “These are governors who have largely proven that they are more in sync with the voters in those states, and what they want and need, than what their party wants from them.”

These Republicans might be expected to draw strong challenges from more conservative candidates, but a popular governor is not a great target, and Republican voters have largely overlooked any left-leaning proclivities their governors exhibit.

“I was a little disappointed when he pulled troops from the border,” said Krista Hudson, 50, an admirer of Mr. Trump who lives in this rural stronghold of Mr. Hogan’s. “But I still support him. This is a Democratic state, and we have always felt ignored and neglected, and we just see him a lot down here.”

Nor have many Democrats stepped up to take on these popular governors. “We should not neglect the fact that the Democrats running are pretty weak,” said Dan Payne, a Democratic strategist in Massachusetts, where aprimary next month will determine who will take on Mr. Baker.

A possible exception is Illinois, where Gov. Bruce Rauner, a Republican, has adopted a largely combative stance against the state’s Democrats. At the same time, he has annoyed his own party so much with his moderate social positions and budget woes that he barely survived a primary in the spring, inspiring a third-party bid from a conservative candidate.

“Bruce Rauner thought he could be Scott Walker when he got elected,” Thomas Bowen, a Democratic strategist and former political director for Mayor Rahm Emanuel of Chicago, said, referring to the Republican governor of Wisconsin. “He forgot that Walker had a supermajority in the state legislature and he did not.”

Image

Bruce Rauner, the incumbent Republican governor, has adopted a largely combative stance with the state’s Democrats, but he has also annoyed his own party with moderate positions on social issues.CreditJose M. Osorio/Chicago Tribune, via Associated Press

“There was a playbook for how to be a Republican in Illinois that’s been replayed over and over,” Mr. Bowen said. “Be fiscally astute, compromise and don’t pick fights unnecessarily.”

Mr. Rauner will face a formidable opponent in J. B. Pritzker, a billionaire venture capitalist. The governor has run several attack ads criticizing Mr. Pritzker’s effort to get a reduction in property taxes on one of his homes, citing the mansion’s lack of working toilets.

In Maryland, Mr. Jealous prevailed in a tough primary for the right to face Mr. Hogan, whose economic agenda he says leaves behind the middle and lower classes. Mr. Jealous wants to expand worker benefits, work toward making Maryland’s public colleges and universities tuition-free, and establish a Medicare-for-all system at the state level.

He is not dissuaded by the governor’s popularity. “We have seen this before, with a popular incumbent governor with a lot of money that ultimately ends with a Democrat winning,” he said. “Our job is to make a positive case for fully funding our schools, getting health care costs under control and get the economy going again.” (Do not, as Mr. Hogan has, suggest that Mr. Jealous is a socialist, unless you don’t mind an R-rated response.)

But under Mr. Hogan, the state has gained tens of thousands of jobs, and businesses and residents welcomed the tax relief he pushed. “People do not want to go back in this state to rampant tax increases,” said Anirban Basu, chief executive of the Sage Policy Group, an economics consulting firm in Baltimore. “Many Marylanders are keenly aware that tax-based growth is suppressed by the state’s high tax rates.”

Simply keeping their seats, however, does not guarantee a successful agenda for Republican governors. A Democratic surge this year could put more of them in the state legislatures, bringing with them more resistance to the governor’s policies.

“It is quite possible that Scott will get re-elected but Democrats will gain enough seats in the legislature that they get veto-proof majority,” said Eric L. Davis, professor emeritus of political science at Middlebury College in Vermont, noting that Mr. Scott had made heavy use of his veto pen in his time as governor.

For all of Mr. Hogan’s successes, especially with the collaborative health care bill, he has also been stymied by Democrats. They overrode his veto of an education bill and forced him to make significant compromises to get tax cuts and transportation measures into law.

Mr. Hogan shrugged it off. “I am mostly in the middle,” he said. “We have a lot more to get done.”

A version of this article appears in print on , on Page A1 of the New York edition with the headline: How to Govern From the Right In a Blue State. Order Reprints | Today’s Paper | Subscribe