Allegations of vote fraud. Charges of corrupt power grabs. Fears of civil strife by angry partisans.

Ripped from today’s headlines? Yes — and no.

While it is unusual for charges of election chicanery to precede the balloting, as they are this year, the spectacle of a closely fought presidential contest whose outcome is challenged as illegitimate is almost as old as the republic itself.

Before President Trump and former vice president Joe Biden debate Tuesday night, here is a look at the aftermath of four close contests over two centuries that stand out as particularly bitter — and could foreshadow what happens after Nov. 3.

1824: ‘Corrupt bargain’ suspicions

Four candidates competed for the presidency in an election held before the advent of the modern two-party system: Secretary of State John Quincy Adams, Treasury Secretary William Crawford, House Speaker Henry Clay of Kentucky and fiery Tennessee populist Andrew Jackson.

When the electoral votes were counted (in six states, legislatures rather than voters chose presidential electors) Jackson led but lacked a majority. That threw the outcome to the House, where under the 12th Amendment to the Constitution each state’s delegation casts one vote for president.

Kentucky’s legislature passed a resolution urging its congressional delegation to vote for Jackson, but Clay viewed the hero of the Battle of New Orleans with scorn. On Jan. 24, 1825, the Kentucky and Ohio congressional delegations announced they would back Adams.

Several days later, a Philadelphia newspaper infuriated Jackson’s supporters by reporting the existence of an arrangement between Clay and Adams. The House speaker would work for Adams’s election in exchange for becoming secretary of state.

“True or not,” Jackson biographer Robert Remini has written, “it seemed so obvious that no one needed proof.”

There were grounds for suspicion. According to Adams’s diary, Clay visited on Jan. 9 and assured him that “he had no hesitation in saying his preference would be for me.” Clay came for a second visit toward the end of the month, according to the diary, and the two men discussed “all the prospects and probabilities of the Presidential election.” The diary, however, makes no mention of a deal.

Adams won the balloting in the House on Feb. 9, 1825, and shared his plan with President James Monroe to make Clay secretary of state. Monroe privately predicted that “it would produce, a very unfavorable effect, on Mr. Adams, & the public, as well as Mr. Clay.”

Despite widespread suspicions of a “corrupt bargain,” Adams submitted Clay’s nomination to the Senate, where it was approved. But Monroe was right: In mid-February Clay was burned in effigy in Pittsburgh, according to a report in the Alexandria, Va., Herald. Jackson “quickly called Clay ‘the Judas of the West’ ” and led a “political holy war” against him, James C. Klotter has written in his biography of Clay.

While most historians dismiss the theory that Adams and Clay reached an explicit quid pro quo, Adams’s presidency never recovered from the circumstances surrounding his election. Four years later, he was soundly defeated by Jackson.

Clay — who failed in 1832 and 1844 to win the presidency — was shadowed by his role in it for the remainder of his political life. The election “was in violation of the will of the people and gave rise to grave suspicions,” the New York Herald concluded in 1871. “It carried its own punishment.”

1876: ‘His Fraudulency’

Things looked very bad for Republicans on election night. Democratic candidate Samuel J. Tilden appeared to have eked out a narrow victory over Republican Rutherford B. Hayes, the governor of Ohio.

“LOST,” the Republican Chicago Tribune declared on Nov. 8, 1876. “The Country Given Over to Democratic Greed and Plunder.”

One newspaper hedged. On the morning other Republican newspapers raised the white flag, the New York Times pronounced the results “still uncertain.”

The night before, Times Managing Editor John C. Reid roused a sleeping (and hung over, according to historian Michael F. Holt) Zach Chandler, the Republican national chairman, with astounding news. There was still a chance, Reid believed, for Hayes to garner the 185 electoral votes needed for victory.

Later that morning, Chandler issued what Holt describes in “By One Vote: The Disputed Presidential Election of 1876” as an “amazingly brazen” statement to the press: “Hayes has 185 votes and is elected.” On Nov. 9, the Times pronounced Hayes the winner under the headline “The Battle Won.”

Threats, charges of corrupt dealings and rumors of insurrection by Democratic partisans filled the next four months. The Memphis Appeal dismissed stories of armed revolt as an attempt by Republicans “to divert the public mind from the infamous schemes by which they proposed to elect Hayes,” but nerves were taut.

Taking no chances, President Ulysses S. Grant deployed U.S. troops around Washington to safeguard the capital.

Congress eventually settled on a 15-member commission to review the disputed results from South Carolina, Louisiana and Florida; its recommendations would have to be approved by the House and Senate. The panel’s bipartisan balance took a severe blow when Supreme Court Justice David W. Davis, a onetime ally of Abraham Lincoln known for his political independence, resigned from the panel after he was elected to the Senate by the Illinois legislature.

His successor, Justice Joseph B. Bradley of New Jersey, was a Republican. One by one, by votes of 8 to 7, the commission approved the Republican returns. Tilden received 50.1 percent of the popular vote, but Hayes was elected president by a single electoral vote.

Backroom bargaining in which Republicans agreed to Democratic demands to remove U.S. troops from South Carolina and Louisiana eased the commission’s recommendations through Congress. “Within five weeks, Hayes had ordered the withdrawal of the last federal troops from the South,” The Washington Post’s Robert G. Kaiser wrote.

Although they lost the White House, Democrats got what they wanted — an end to Reconstruction and the post-Civil War commitment to defend the civil and political rights of formerly enslaved Black Americans.

Nevertheless, many remained unreconciled. A new Democratic newspaper in the nation’s capital, The Washington Post, routinely referred to Hayes as “His Fraudulency.”

1960: ‘The Machine came through’

“Kennedy Nears Victory,” the banner front-page headline on The Washington Post declared Nov. 9, 1960. But Democrat John F. Kennedy’s victory over Republican Vice President Richard Nixon needed a little help from some friends.

Early returns from the battleground state of Illinois initially looked promising for the Democratic nominee. Kennedy held “a wide lead,” United Press International reported, “despite a midnight spurt” by Nixon. That “spurt” intensified over the next few hours, pushing Nixon into the lead and Sargent Shriver, Kennedy’s Illinois campaign manager, into despair.

“I was devastated,” Shriver told The Post’s Peter Carlson in 2000. “I thought that the fact that I had lost my state, Illinois, would mean that Kennedy would lose the presidency.”

It turned out that Shriver’s worries were premature. Republicans noticed that returns from a number of Chicago precincts controlled by Mayor Richard J. Daley had yet to come in, Carlson wrote — and when they did, they went overwhelmingly for Kennedy. Late returns pushed Kennedy to a paper-thin victory of almost 9,000 votes, and Nixon’s operatives smelled a rat.

Along with Texas, another state where Republicans believed vote fraud had occurred, the victory in Illinois gave Kennedy the White House. “It was a ‘must’ election and the Machine came through and won,” Mike Royko wrote in “Boss.” But Kennedy’s win might not have been the highest priority for Daley, whose administration had been buffeted by a police corruption scandal pursued by Republican State’s Attorney Benjamin Adamowski.

Recounts from disputed precincts showed little change in Kennedy’s totals, according to Royko, but revealed a major shift of votes in favor of Adamowski. It wasn’t enough to overturn his defeat but was significant enough to indicate “that the Machine was more concerned with beating Adamowski than electing Kennedy,” Royko wrote.

In Texas, home state of Kennedy running mate Sen. Lyndon B. Johnson, Republicans uncovered abundant evidence of inflated returns favoring Kennedy and demanded a recount. “But there was no recount,” according to Carlson. “The Texas Election Board, composed entirely of Democrats, had already certified Kennedy as the winner.”

2000: ‘Is it Bush?’

It was an election night like no other in the nation’s history. After a bruising campaign between Democratic Vice President Al Gore and Republican George W. Bush, the governor of Texas, Americans settled in to follow the returns.

Those who stayed up through the night incurred a severe case of whiplash.

Early Tuesday night, based on exit polling, the networks awarded the battleground state of Florida to Gore, making him the likely winner of the election. Several hours later, as returns threw that projection into doubt, they reversed themselves and called Florida for Bush. A third reversal came early Wednesday morning: With Gore suddenly gaining ground, the networks decided the state was too close to call — and so was the outcome of the presidential election.

“We don’t have egg on our face — we have an omelet,” NBC’s Tom Brokawtold viewers. Many newspapers scrambling to make deadlines put the wrong winner on their front page or changed headlines between editions as the results ricocheted during the night. “Is it Bush?” one edition of the Orlando Sentinel had as a headline.

That was just the start. Battalions of out-of-state Democrats and Republicans descended on Florida as four counties — Broward, Miami-Dade, Palm Beach and Volusia — became the focus of the recount battle. New phrases entered the political lexicon: “Hanging chads” (pieces of punch-card ballots that remained attached after a vote was cast) and the “butterfly ballot” (a two-page design used in Palm Beach County that confused voters into voting for conservative Reform Party candidate Patrick Buchanan instead of Gore).

The ballot battle grew intense. On Nov. 22, a demonstration involving Republican operatives dubbed the “Brooks Brothers Riot” forced canvassers in Miami-Dade County to halt their manual recount.

“We scared the crap out of them when we descended on them,” Bush campaign operative Brad Blakeman told The Post’s Michael E. Miller in 2018. The canvassers “knew what they were doing was breaking the rules and totally subjective, so they all met and decided to put an end to it.”

Joe Geller, then the Democratic Party chairman in Miami-Dade and a witness to the incident, takes a darker view. “Violence, fear and physical intimidation affected the outcome of a lawful elections process,” he told Miller. “I think that’s pretty bad.”

On Dec. 12, 2000, the U.S. Supreme Court ordered a halt to a recount authorized by the Florida Supreme Court in a decision that made Bush the winner of the election. Subsequent investigations by the Miami Herald and other news organizations concluded that the recount authorized by the Florida Supreme Court would not have changed the outcome.

That is little comfort to Ron Klain, then an aide to Gore. “I am not over it,” Klain told the Atlantic in its oral history of the 2000 Florida recount battle. “I don’t think I’ll ever be over it.”

Read more Retropolis: