From "Morning in America" to "Yes, we can," presidential elections have long seemed like contests in optimism: the candidate with the most upbeat message usually wins. In 2016, that seems to have been turned on its head: America is shrouded in a most un-American pessimism.

The gloom touches race relations, which — after the shooting of white police officers by a black sniper in Dallas, and Black Lives Matter protests against police violence, followed by arrests, in several cities — seem to get ever worse. It also hangs over the economy. Politicians of the left and right argue that American capitalism fails ordinary people because it has been rigged by a cabal of self-serving elitists. The mood is one of anger and frustration.

America has problems, but this picture is a caricature of a country that, on most measures, is more prosperous, more peaceful and less racist than ever before. The real threat is from the man who has done most to stoke national rage, and who will, in Cleveland, accept the Republican Party's nomination to run for president. Win or lose in November, Donald Trump has the power to reshape America so that it becomes more like the dysfunctional and declining place he claims it is.

The dissonance between gloomy rhetoric and recent performance is greatest on the economy. America's recovery is now the fourth-longest on record, the stock market has hit all-time highs, unemployment is below 5 percent and real median wages are at last starting to rise. There are genuine problems, particularly high inequality and the plight of low-skilled workers left behind by globalization. But these have festered for years. They cannot explain the sudden fury in American politics.

On race relations there has, in fact, been huge progress. As recently as 1995, only half of Americans told pollsters that they approved of mixed-race marriages. Now the figure is nearly 90 percent. More than one in 10 marriages are between people who belong to different ethnic groups. The movement of nonwhites to the suburbs has thrown white, black, Hispanic and Asian-Americans together, and they get along just fine.

Yet despite all this, many Americans are increasingly pessimistic about race. Since 2008, when Barack Obama was elected president, the share of Americans who say race relations are good has fallen from 68 percent to 47 percent. The election of a black president, which seemed the ultimate proof of racial progress, was followed by a rising belief that race relations are actually getting worse.

What explains the divergence between America's healthy vital signs and the perception, put with characteristic pithiness by Trump, that the country is "going down fast"? Future historians will note that from about 2011 white and nonwhite babies were born in roughly equal numbers, with the aging white population on course to become a minority around 2045. This was always going to be a jarring change for a country in which whites of European descent made up 80 percent to 90 percent of the population for about 200 years: from the presidency of George Washington to that of Ronald Reagan.

Demographic insecurity is reinforced by divisive partisan forces. The two parties have concluded that there is little overlap between the groups likely to vote for them, and that success therefore lies in making those on their own side as furious as possible, so that they turn out in higher numbers than the opposition. Add candidate Trump, whose narcissistic bullying has prodded every sore point and amplified every angry sentiment, and you have a country that, despite its strengths, is at risk of a severe self-inflicted wound.

The damage would be greatest were Trump to win the presidency. His threats to tear up trade agreements and force American firms to bring jobs back home might prove empty. He might not be able to build his wall on the border with Mexico or deport the 11 million foreigners currently in the U.S. who have no legal right to be there. But even if he failed to keep these campaign promises, he has, by making them, already damaged America's reputation in the world. And breaking them would make his supporters angrier still.

The most worrying aspect of a Trump presidency, though, is that a person with his poor self-control and flawed temperament would have to make snap decisions on national security — with the world's most powerful Army, Navy and Air Force at his command and nuclear-launch codes at his disposal.

Betting markets put the chance of a Trump victory at around 3 in 10 — similar to the odds they gave for Britain voting to leave the European Union.

Less obvious, but more likely, is the damage Trump will do even if he loses. He has already broken the bounds of permissible political discourse with his remarks about Mexicans, Muslims, women, dictators and his political rivals. It may be impossible to put them back in place once he is gone. And history suggests that candidates who seize control of a party on a prospectus at odds with that party's traditional values tend eventually to reshape it. Barry Goldwater achieved this feat for the Republicans: Though he lost 44 states in 1964, just a few elections later, the party was running on his platform. George McGovern, who fared even worse than Goldwater, losing 49 states in 1972, remolded the Democratic Party in a similar fashion.

One lesson of Trump's success to date is that Republicans' old combination of shrink-the-state flintiness and social conservatism is less popular with primary voters than Trumpism, a blend of populism and nativism delivered with a sure touch for reality television and social media. His nomination could prove a dead end for the Republican Party. Or it could point toward the party's future.

When contemplating a protest vote in favor of tearing up the system, which is what Trump's candidacy has come to represent, some voters may wonder what they have to lose. (That is the logic that drove many Britons to vote for Brexit on June 23.) But America in 2016 is peaceful, prosperous and, despite recent news, more racially harmonious than at any point in its history.

So the answer is: an awful lot.

Copyright 2013 The Economist Newspaper Limited, London. All Rights Reserved. Reprinted with permission.