Regardless of whether Donald Trump or Hillary Clinton wins November’s election, the next president faces what looks to be a nearly impossible task when it comes to governing: Persuading the other side to compromise.

With the House likely to remain in Republican hands and neither party likely to hold a filibuster-proof Senate majority, successful dealmaking with Congress by the next president would have to overcome massive partisan divisions. Holding your breath doesn’t seem advisable.

But one route to legislative success may lie with the public. If a president could persuade “out-partisans” — citizens who identify with the opposite party — to view her or him as more likeable and trustworthy, perhaps that could put pressure on Congress to compromise. For instance, if a President Clinton could win over some Republican identifiers, GOP members of Congress might be more willing to cut deals with her.

But in an era in which partisan animosity is pervasive, is winning over the other side even possible?

My research suggests that it is — as long as presidents are willing to alienate their own party’s base.

In a series of studies, I find that partisans indeed become more favorable toward, and more trusting of, an “out-party” politician when they do something to displease a key group in the party’s coalition. This also leads them to be more supportive of compromise between the governor and their own party’s politicians.

In one survey experiment, I randomly assigned respondents to read a news story about their own governor. The news article reported that the governor had done something to either please or upset key groups in his or her party’s coalition. For Republican governors, this meant pleasing or upsetting evangelical Christians, business groups and gun rights groups. For Democratic governors, the relevant groups were labor unions, environmentalists and African Americans.

Respondents were then asked to rate the trustworthiness of the governor, as well as how supportive they were of “policy compromise” between the governor and the opposing party. Among out-partisans — people who did not share the governor’s party affiliation — those who read about the governor alienating his or her base rated the governor as 15 percent more trustworthy than respondents who read about the governor doing something to please the base. Those respondents were also between 9 and 14 percent more supportive of policy compromise.

In other words, out-partisans were more trusting of the governor and were more willing to encourage their own party leaders to compromise when the other party’s governor had done something to upset his or her core constituency.

Why did this happen? One reasonable guess would be specific policies. If a Democratic governor refused to sign into law any gun-control legislation, for example, it would no doubt upset groups in the Democratic Party’s base, and at the same time earn the governor greater trust from Republicans.

But in fact, the experimental manipulations made no mention of high-profile, controversial policies. Moreover, the policies that were discussed in each of the experiments did not vary across conditions, and therefore cannot explain my findings.

Instead, I suggest that the results stem from the fact that many Americans tend to conceptualize parties as “teams of groups” and react to politicians’ actions based on how they treat those groups. Building on previous studies of partisan coalitions and party identification, I argue that most people have a sense — perhaps based on voting patterns — that certain kinds of people are Democrats, while other kinds of people are Republicans.

Thus, when people see the party affiliation of a governor or president, we don’t just see a “D” or an “R” — we see the agent of a particular set of societal groups. And when someone does not feel favorably toward one or more of these groups (e.g., racial minorities, gun rights activists, environmentalists or religious conservatives), trusting — let alone compromising with — the politician simply won’t feel right.

But that can change if that politician turns out not to be a fully loyal “team player.” In other words, despite having a particular party label, if out-party executives alienate the groups voters assumed they were aligned with, then perhaps these executives can be trusted after all.

Although my experiments focused on state governors, I also found a similar dynamic in attitudes toward President Obama surrounding the 2010 budget compromise with congressional Republicans. During that episode, Obama was widely reported to have disappointed the base of his party by agreeing to extend the Bush-era tax cuts.

And consistent with the experimental results, Republicans in the public became significantly more favorable toward Obama (by roughly three percentage points) after the event, according to my analysis of a series of national surveys.

Of course, none of this is to say that leaders should alienate the groups in their party, nor is it to say that there isn’t a cost to such behavior. Both in my experiments and national polling data, I also find that partisans significantly lower evaluations of their own party’s executives who alienate groups in the party’s base.

But if one believes that government needs to act on any variety of pressing issues and that doing something is better than partisan bickering and unrelenting gridlock, then these findings suggest one possible pathway to cooperation. All else equal, my research suggests that a president who signals a willingness to alienate his or her party’s base, even symbolically, will create more opportunities for legislative compromise than a president who does not.

At this point, it is unclear whether that is more likely to describe Donald Trump or Hillary Clinton. But, to the extent that we want government to get something done in the next few years, it’s worth thinking about which candidate that might be.

John V. Kane is a PhD candidate in the department of political science at Stony Brook University.