It’s 1980 all over again. A media celebrity runs for the GOP nomination—something he has been planning for years—and sweeps the primaries, rattling the Republican establishment along the way. That’s the story of Ronald Reagan as he mobilized for what would be his landslide 1980 victory. And it is the story of Donald Trump too.

Trump and Speaker Paul Ryan met in an effort to heal the wounds that have opened up in this brutal primary. Come convention time, if history is any indicator, they will join together. But it is likely to be a rocky road. The same was true in 1980.

Today Republicans lionize Reagan and remember him as the quintessential coalition-builder. He brought the Republican Party together, unlike Donald Trump, who spent the spring tearing the GOP apart. But the truth is that in real time in 1980, Reagan was seen as the outside antiestablishment candidate. He was also seen as less than a serious contender, even when it looked like he would secure the nomination.When the Republican primary season started out, he was the only one out of seven candidates who had not held a government position inside Washington, a roster that included two senators, three congressmen, and a Treasury Secretary. Instead, Reagan was best known for his starring roles in middle-brow American movies, a career he parlayed into a run as California governor. When he announced his candidacy, critics derided him as the “celebrity in chief.”

Reagan held himself up as the icon of conservatism but, much like Trump, his past suggested a history of political flexibility if not outright liberalism. He had once been a Roosevelt Democrat. By the 1964 presidential race, he’d endorsed the GOP’s Senator Barry Goldwater and made his conversion to full-fledged conservative.

Still, in his years in the California governorship, Reagan continued to demonstrate political flexibility. He supported abortion rights, welfare spending, and, when necessary, tax increases. True, he called for cracking down on campus unrest. And by now his hallmark issue was fierce anticommunism as well as anti taxation. But Reagan understood that he governed in a state where ideological purity would not have secured for him the office he sought given that Democrats greatly outnumbered Republicans.

And yet in 1980 Reagan ran as the standard bearer of the Republican Party. Throughout the primary season, there was deep skepticism. George H.W. Bush was the presumptive establishment candidate. He had been a congressman, the Republican National chairman, an ambassador to the UN and China, and the CIA director. Bush’s early victory in the Iowa caucus suggested that voters were not sold on the movie star.

But Reagan was onto something, much the same way that Trump is. After a decade of slow growth, declining productivity, double-digit inflation—and an energy crisis that graphically demonstrated the government’s incapacity to solve problems—America was eager for solutions. What people hungered for more than anything else was leadership. Jerry Rafshoon, President Carter’s adviser, told him, ”People want you to act like a leader.”

And that is what Reagan understood. In short, digestible sound bites, he promised Americans that they would once again be great. On foreign policy, he would bring peace through strength. If Trump promises to build a wall, Reagan would tear one down. And on domestic policy, he would cut taxes. To Trump’s protectionism, Reagan offered supply-side economics. The master of media knew a winning platform when he saw it.

The establishment was slow to rally behind him. With the disastrous memory of 1964, when Barry Goldwater and his brand of conservatism lost in a landslide, Reagan seemed too risky. Moderates worried that his fierce anticommunist rhetoric would escalate tensions with the Soviet Union—even Barry Goldwater called him “trigger happy”—while mainstream fiscal conservatives said his budget numbers did not add up. Bush denounced this policy as “voodoo economics.”

Gerald Ford called Reagan “unelectable” in late March. Many Washington insiders and party regulars saw Reagan as too extreme and hoped that the former president would throw his hat in. Indeed, early polls showed Ford with greater appeal than Reagan among Democrats, a serious liability in a race where Republicans would need to attract cross-over voters to win. In early match ups, Ted Kennedy, who was challenging Carter from the left in the Democratic primary, beat Reagan by as much as 64 to 34 percent.

And age seemed a problem too. Reagan turned 69 a month into the primaries and, if elected, would surpass William Henry Harrison as the oldest president, who in 1841 caught a cold delivering his inaugural address, developed pneumonia, and died a month later. A Newsday reporter said Reagan was in a “race against time.”

He was also vulnerable as a celebrity. Reagan was, as one commentator explained, a “the end product of television politics . . . It is a show and he’s a star actor.” That was not a compliment.

Reagan won in New Hampshire, but the primary season was long and drawn out. In Massachusetts, he came in third behind Bush and John Anderson, the Illinois Senator who dropped out of the Republican contest and ran as an Independent. The conventional wisdom maintained that Anderson would draw votes from Carter as a moderate alternative, but nevertheless, his presence in the race suggested that the electorate might not be ready for Reagan’s brand of conservatism.

Indeed, Bush scored important victories in Pennsylvania and in Michigan. As Bush did well, some rallied behind Reagan, including Senator Howard Baker, who dropped out of the race, saying: “Only divisions from within our party can keep us from benefiting from the bitter divisions within the Democratic Party. The time has come to give Ronald Reagan our prayers, our nomination, our enthusiastic support.”

But the primary season did not come to an end until late May when, at last, Reagan secured enough delegates to win the nomination. And even then, many embraced Reagan only as an act of political pragmatism. As Ohio Governor James Rhodes explained, “I love George Bush. I love Gerald Ford. I love Ronald Reagan. Sometimes in love you have to make your choice. My choice is Ronald Reagan.”

As the GOP convention drew closer, other leading Republicans fell in line, among them the most senior liberal Republican, Senator Jacob Javits. He had refused to endorse Goldwater in 1964, but now he cast his lot with Reagan. With the endorsement, Javits would be a delegate at large. “I felt it was important for me to have an input,” he said, “and I knew I couldn’t have it unless I cast my vote for Reagan.” The New York senator was up for reelection, and he also believed that the GOP had a chance, with Reagan at the head of the ticket, to reclaim the Senate. (It did, but without him—Javits was upset in the Republican primary by the more conservative Al D’Amato)

But the prospect of party disunity did not end at the convention. Now it was the Republican right’s turn to fret about its candidate. When Reagan announced that he was selecting George Bush as his running mate, a decision that came only at the end of the convention and after much media speculation, the right threatened to walk. In 1976, Reagan had subverted his effort to win the Republican nomination over President Gerald Ford when he announced that his running mate would be Pennsylvania Republican Richard Schweiker, a liberal Republican who was antithetical to Reagan’s conservative claims. Now he seemed to be toying with moderation once again.

With evangelical voters mobilizing at the grassroots and many entering electoral politics for the first time, the leaders of this new social force wanted someone who would fight for their causes. Paul Weyrich, the head of right-wing Committee for the Survival of a Free Congress, was angry. “I feel no need obligation to bring about our own destruction,” Weyrich thundered. “I won’t support a Reagan-Bush ticket.”

Reagan attempted to appease the right by signing onto a platform that dropped the ERA and called for an anti-abortion amendment. He also called evolution just a “theory” and expressed skepticism about the man-made causes of pollution. But the establishment was still worried. Texas Senator John Tower, who chaired the convention’s platform committee, warned his colleagues, “Republicans have a singular facility sometimes for snatching defeat from the jaws of victory. Disunity has cost us elections in the past.” Nevada Senator Paul Laxalt said the new right is “afraid of Ron.”

The general election was far from a shoo-in. The polls were all over the place, including placing President Carter ahead of the insurgent candidate. In the end, Reagan scored a decisive victory. But his success, and the ingredients that allowed for this landslide victory, were clear only in hindsight. A week before the election, it was too close to call.

Rather than moderating his rhetoric and toning down his platform in the general election, Reagan stepped up his game. He blamed Carter personally for the gas lines that had signaled the decline of American strength and prosperity. It was Carter’s fault that Iranian terrorists seized the American embassy in Teheran and held American hostages. And Carter’s efforts to negotiate nuclear deals with the Soviets were a disaster.

Reagan was a master of the sound bite: "A recession is when you lose your job, a depression is when your neighbor does, and a recovery is when Jimmy Carter does.” And he told a narrative that simultaneously devastated Carter while instilling confidence in him. His signature campaign slogan captured it all: “Are you better off than you were four years ago?”

These messages appealed to independent voters and white working-class voters, the so-called Reagan Democrats, who were suffering from slow growth and stagnant wages as they saw jobs disappearing overseas. Reagan also eagerly embraced the race card. He went after white voters in the South, saying he was a defender of states’ rights near where civil rights workers had been brutally murdered in 1964. He denounced “welfare queens in fashion jeans” as the embodiment of excessive government waste, another not so subtly coded racial message.

1980 was also the first gender gap election when there was a clear discrepancy between how men and women voted. Reagan’s cowboy swagger and tough sounding rhetoric appealed to men. Lee Atwater explained it wasn’t so much that women didn’t like Reagan, it was just that men liked him so much.

If 1980 is any indicator of how an unlikely outspoken conservative candidate with a liberal background could win, Trump is well on his way. And Reagan did not just win; he won in a landslide, one that many did not see coming, and one that severely weakened much of the liberal agenda and put the country on a rightward path that still shapes politics today. Like Reagan, Trump has dominated the primaries, worried the establishment, and yet reveals himself to have deep-seated support. Like Reagan, he is the master of a new media to mobilize and rally supporters, especially white men. In spite of the media criticism he receives as running a post-policy campaign, his supporters feel he provides solutions and refreshingly says what he wants.

Just as Reagan did, Trump has had his eye set on the White House for a long time. In a 1990 Playboy interview, he said, “I hate seeing this country go to hell. We are laughed at by the rest of the world.” He also said, “Vision is my best asset. I know what sells and I know what people want.” Like Reagan, he has spent decades crafting his message. And so far his strategy seems to be working.