The story of Rutherford Bichard Hayes', a Republican lawyer from Ohio, election to the presidency is well known- he won by just one vote, after all.
In the beginnings of Reconstruction in 1876, Hayes faced off against Democratic nominee Samuel Tilden to run the country. The incumbent Republican president, Ulysses Grant, oversaw an economic downturn, which was a blow to Republican popularity. In fact, three days after the election, the electoral votes were 184-165 in Tilden's favor. At the time, the necessary number of electoral votes was 185, leaving Tilden just one short. Florida, Louisiana, and South Carolina's votes were not decided, as both parties were accused of fraud, leaving 20 disputed votes.
A commission of 5 representatives, 5 senators, and 5 Justices met to vote on which candidate would be awarded all 20 disputed votes. Of the 15 officials, 7 were democratic, 7 were Republican, and the sole mostly-independent was Joseph Bradley. Bradley and the 7 Republicans voted for Hayes, winning the election for Hayes by 8-7 within the commission and 185-184 for the whole country.
Of course, this incredibly close election outraged Southern Democrats, many of whom were fed up with Radical Republicans leading the country. Protests even included talk of a march on Washington, though Grant increased security and no such march took place. To appease the Democrats to accept the commission's decision to make Hayes president, the Republicans negotiated with the Democrats to decide what is now known as the Compromise of 1877.
In this compromise, Republicans agreed to remove all federal troops from former Confederate states, appoint one Southern Democrat to Hayes' cabinet, build a transcontinental railroad, and help industrialize the South in exchange for the South's peaceful acceptance of the transition in presidents. For these concessions, many Radical Republicans looked down on Hayes' administration. Starting from Hayes' presidency, the Republican party started a noticeable shift away from civil rights issues and towards economic issues.
During his term, Hayes tackled corruption in businesses and political parties. He opposed the spoils system and the exchange of money for gold, helping to reverse the effects of the Panic of 1873 in the process. He strongly enforced the Monroe Doctrine in terms of Latin America, helping to settle disputes and keep France away from Colombia and Panama. He laid the groundwork for the Chinese Exclusion Act, a race-specific restricting immigration bill passed after his term.
Democrats had sought to impeach Hayes during his term, but due to Republicans, the plan never saw fruition. Hayes declined to run for re-election and left the presidency in 1881.
Sources: Miller Center, Wikipedia, White House.gov, Potus.com