Before the 1870s there were different parties that sprouted up and did well. The whigs, federalists, Democratic-Republicans, all rose and fell. But ever since the post civil war just these two parties have dominated everything.
How have they been able to keep going so long? Why has neither fallen apart or been beaten by a new party?
Well, you have to understand first of all that the First Past the Post electoral system makes it very difficult for third parties to break through. Second, to understand why those parties fell, one must be mindful of the circumstances that led to it in the first place. Starting with the Federalists (primarily politicians who agreed with Alexander Hamilton's vision for the country that we should have a strong centralized government with an economy built around trade, banking, etc). The Democratic-Republicans emerged out of the ideas of Thomas Jefferson, who believed in a radical agrarian nation with a limited federal government and powerful individual states.
After Hamilton's death, the Federalists were completely guileless politicians that had such a disdain for the average person (indeed they likened democracy to mob rule, and always preferred the very limited suffrage in Britain over the idea of republican France). That strategy really isn't conducive to winning elections and at the local level they could not match the Democratic Republicans well oiled organization. Because the Federalists had such a narrow base of support and after being discredited through several attempting to secede New England (their lone power base) from the United States, most practical politicians abandoned them and also became Democratic Republicans. For a brief period the U.S. existed as essentially a one party state. Of course, because the Democratic Republicans had become such a big tent, they essentially had multiple wings and tendencies now and it was no longer the party of just Jeffersonian agrarianism. Indeed, Henry Clay was a Democratic Republican and his "American System" was anathema to the still living Jefferson. It was a policy of high tariffs, aggressive public works spending, and a national bank... On the other end you had Democratic Republicans who opposed this system. These wings could not co-exist. The 1824 election was really the deciding factor in the split. You had four very different candidates all under one party banner: John Quincy Adams, who largely supported the American System, but actually wanted to take it even further (he promoted the idea of a public university for example, and many of his proposals actually alarmed even Clay as a governmental overreach), Clay, William H. Crawford, who had been an industrious Treasury Secretary, and who represented the southern interests of the party (free trade, anti internal improvements, etc), and Andrew Jackson, who opposed most of the American System, but primarily ran as a war hero. Adams was elected by the House (after Clay, who almost assuredly would've won if he'd finished in the top three, but he didn't was eliminated from consideration) and promptly appointed Clay Secretary of State (the so called "her apparent" cabinet position). The Jackson supporters howled that this was a corrupt bargain (but what very few people even know today is that Adams actually wanted to put both of his other opponents in the cabinet as well. He wanted Crawford to return to Treasury, but his stroke and physical debility made that impossible, and he wanted Jackson to be his Secretary of War. Jackson declined). Jackson's supporters bolted the party and formed the Democratic Party. The remainder changed their names to the National Republican Party and after Jackson's election in 1828, the Whigs (taking the name from the British Whigs opposition to excess crown authority. They took to calling the imperious Jackson "King Andy"). That lasted until 1856. Why did the Whigs disappear?
The reason the Whigs disappeared is because unlike the Democrats, they couldn't finesse slavery. The Democratic Party always supported the institution of slavery, even if there were diligent anti-slavery Democrats (such as David Wilmot, who, like most of his fellows, eventually bolted the party, first for the Free-Soil Party, and then for the Republicans). The Whigs just couldn't figure out how to get around it. Southern Whigs were just as pro-slavery as most Democrats. Northern Whigs were anti-slavery, and some were radically so. The Whigs initially thought they could make a comeback during the Pierce Presidency, but things just overtook them. Primarily the anti-Nebraska coalition of anti-slavery Democrats, Free Soilers, and radical Whigs that fused together and called themselves "Republicans". At the same time, a once semi-secret club (indeed their Know Nothing name came from what they would say when asked about the club) that was anti-Catholic, anti-immigration (especially Irish), and conspiracist formed itself a political party called the American Party. The Whigs essentially were pulled in multiple directions. Some becoming Know-Nothings, including Millard Fillmore who encouraged his supporters to join and finally the death blow was William Seward leaving the Whigs and taking his supporters into the Republican Party. Since then, each party has become entrenched and because they've both proven to be so elastic in their views (both parties have changed ideologies and positions on the political spectrum multiple times. The Democrats went from a right wing party to a left wing party and the Republicans have gone from a left wing party to a right wing one over the course of a couple hundred years), there's no reason for people to bolt to third parties like in the past. They can just bolt to the other party instead (the Trump era really highlights this sort of thing as both sides saw an influx of members from the other party joining in either support or opposition to Trump).