When President-Elect Rutherford B. Hayes raised his hand and took the oath of office on the East Portico of the Capitol on March 5, 1877, his supporters breathed a sigh of relief. The ceremony marked the end of a lengthy, acrimonious debate between his Republicans and the Democrats over the results of the previous year’s election. Some even believed the tension might threaten to spill over into another Civil War.

Democratic nominee Samuel Tilden had earned the popular vote, and 184 of the 185 votes he needed in the Electoral College. But allegations surfaced that Tilden’s seeming victory was thanks, in part, to voter intimidation and fraud in key states like Florida, Louisiana, and South Carolina. A special Congressional committee was formed to sift through the paper trail, leaving the outcome in doubt for months.

Hayes being sworn in ended all speculation. But only a handful of people observing the ceremony knew that the celebration taking place that Monday was merely for show: Hayes had been sworn in during a secret ceremony two days earlier, in the presence of outgoing president Ulysses S. Grant. And history still isn’t quite sure why.

In the years following the Civil War, Reconstruction and bitter feelings had created a state of discontent. For the 1876 election, both of the major political parties knew the country would be looking for a president who was tempered in his actions.

The Democrats sided with Samuel Tilden, who made his name as governor of New York by breaking up a corrupt political scene headed by “Boss” Tweed; Republicans backed Rutherford B. Hayes, a Civil War veteran and Ohio governor who was so moderate in every aspect of his life—he abstained from alcohol—that it would be virtually impossible for him to stir up any radical opposition.

Political pundits who predicted a tight race weren’t disappointed. As the results began trickling in on November 7, 1876, Democrats crowned Tilden as the victor, with a winning popular vote margin of 250,000. But four states—Florida, Louisiana, South Carolina, and Oregon—quickly became areas of contention. Democrats were plagued by allegations of intimidating newly empowered black voters to side with Tilden in three of those key territories; Democrats accused Republicans of foul play in Oregon.

Hayes needed 185 electoral votes. He had 184 to Hayes’s 165. Twenty electoral votes were in doubt. As the weeks went by, no one knew who the President-Elect was.

To break the logjam, Congress appointed a special Electoral Commission to investigate the results. Five Republican Congressmen joined five Democrats and five Supreme Court justices. It took them until February 1877 to come to a majority vote of 8-7 in favor of Hayes. He was President-Elect by one commission vote, possibly the narrowest margin of victory in any presidential election.

That decision did little to soothe the Democrats, who were incensed that their idea of the rightful winner was being denied his seat in the Oval Office. Extensive filibustering took place in the House that delayed acknowledgment of the commission’s decision. Rumors began to swirl that Tilden’s more ardent supporters might show up to Washington armed, with an eye on kidnapping Hayes so Tilden would be invited to take his place. One irate Tilden supporter shot a bullet into the window of Hayes’s home.

As Hayes and his wife, Lucy, began making the trip from Ohio to Washington, they had no idea if he was actually president. They were still traveling when they got the official announcement, which was made on March 2. The Democrats had finally ceded their point, albeit with concessions: They’d gain a Democrat postmaster general, as well as the removal of federal troops from government buildings, effectively ending Reconstruction.

When Hayes arrived in Washington on March 3, he was invited to dinner by outgoing president Ulysses S. Grant. At some point during the evening, Grant took Hayes to the Red Room in the White House and stood nearby as Supreme Court Justice Morrison B. White administered the oath of office. After the kidnapping rumors and the Democratic response, Grant may have desired a private and controlled inauguration that couldn’t be disrupted.

The two returned to dinner, their guests unaware of what had just taken place. As a result, March 3 was a day when the country had two commanders-in-chief.

The (second) Hayes inauguration. Senate.gov

Hayes had his official ceremony two days later. With Democrats appeased by the concessions, there were no disruptions. Still, Grant walked Hayes to the podium, protective of the President-Elect until his last moments as president were completed.

The U.S. Senate’s official reason for Hayes being sworn in early cites the calendar as the main issue. Inauguration day fell on a Sunday that year, and the Constitution contains no explicit protocol for what to do. To not swear in Hayes on Sunday and wait until Monday would technically mean the country would be without a president for a day. Dwight Eisenhower took similar dual oaths in 1957 for that reason.

But few elections had been as hotly contested as Hayes vs. Tilden, with the scars of the war still fresh. Grant may have seen potential for Democrats to disrupt the ceremony to the point where he felt it best to make Hayes’s appointment official as soon as possible. To delay might have meant Grant’s exit on March 4 would leave a void in office.

In the end, Hayes was as advertised, almost demure in his service—he and his wife even banned alcohol from the White House—and exited in 1881 just as quietly as he had come in.

It would’ve taken a true political historian to notice that his March 5 inauguration was a duplicate, but there was one clue for the observant. When Hayes arrived at the East Portico to be sworn in, he was sitting on the right of his carriage, a spot that was always reserved for just one person: the President of the United States.