Because the US electoral system is a winner-take-all contest that is decided on the basis of districts and states, its most stable configuration consists of two, and only two, major parties (a situation known in political science as "Duverger's Law"). There have been several instances in US history where "Third Party" candidates have run in elections, sometimes getting significant portions of the vote (Teddy Roosevelt and the Bull Moose Party, Ross Perot's Reform Party). But one of the most successful of these Third Parties was the Socialist Party of the early 20th century.
The Socialist Party was the more radical rival of the Populist Party. While the Populists drew most of their support from rural farmers, the Socialist Party had its strongholds among industrial workers in the urban factories and among unionized miners in the West.
The first major socialist group in the US was the Socialist Labor Party (SLP), founded in 1877. In 1900, the SLP merged with the newer Social Democracy of America, founded by railroad union organizer Eugene V. Debs, to form the Socialist Party of America. The Socialist Party shared the anti-corporate and anti-capitalist program of the IWW—indeed, Debs himself was one of the co-founders of the IWW. Unlike the Wobblies, though, who focused on direct action in the workplace through radical trade unionism, the Socialist Party worked from within the electoral process. As advocated by Debs, the basic strategy of the Socialist Party was to capture the machinery of local governments and use them to support the local progressive movements (including women's suffrage and the labor unions), and use that base to seek higher and higher levels of office. The electoral arm of the socialist movement and its militant non-electoral arm (the IWW) were to be partners, each using the methods at its disposal to help the other reach its goals, and together strengthening the entire socialist movement. Local mayorships were particularly important to the Socialists--local mayors often sent police to break strikes and shut down union gatherings, and having a Socialist as mayor meant that the local movements didn't usually have to fear those things. (When the IWW went on strike in Paterson, New Jersey, in 1913, for instance, the mayor of Paterson sent in the cops to break heads--and the IWW responded by moving its meetings to the Botto House in the neighboring city of Haledon, which had a Socialist Mayor.)
With their strong base among the progressive social movements, the Socialists soon became one of the most successful third parties in American politics, and no Third Party since then has matched their electoral successes. From 1900 to 1920, in over 100 urban areas, particularly in the northeast and the west, Socialists dominated the local elections. In 1914, in the state of Oklahoma alone, 175 Socialists were elected to local and county office, including mayors and city councils, and 3 Socialists were elected to the state legislature. In 1911 alone there were 74 Socialist mayors in the United States. During the 1910's and 1920's, Milwaukee, a strong union center, repeatedly elected a Socialist mayor, and Socialist Mayors were also elected in Butte, Montana; Reading, Pennsylvania; Schenectady, New York; Flint, Michigan; Pasadena, California; Minneapolis, Minnesota; Coeur d'Alene, Idaho; Oklahoma City, Oklahoma; Berkeley, California, and many smaller cities. In 1918, the Socialist Party held 32 seats in the nation's state legislatures. In 1910, Socialist Party candidate Victor Berger was elected to the US House of Representatives for Wisconsin's 5th District to become the first Socialist in Congress, and in 1914 fellow Socialist Meyer London of New York joined him in office. Eugene V. Debs ran for President on the Socialist ticket four times, polling as high as 6% of the popular vote. In 1920, Debs won almost a million votes, 3.4% of the total, despite the fact that he was in jail at the time on sedition charges (his campaign slogan was "Vote for Prisoner Number 9653"). Debs got 16% of the vote in Nevada and Oklahoma, 11.6% in California, 10% in Montana, Arizona, Washington and Idaho, 8% in Wisconsin, and 4% in New York.
After the US entered the First World War, Woodrow Wilson passed the Espionage and Sedition Acts, which made it a crime to criticize the war or to say or print anything that was, in the words of the law, “disloyal”. Socialist Congressman Meyer London cast the only vote against it. Written specifically to target the radical socialist movement, the laws had the intended effect. Thousands of IWWs, Socialists, Anarchists, and, after the 1917 Russian Revolution, Communists, were rounded up and arrested on the flimsiest of pretexts (the largest of these mass arrests were known as the Palmer Raids, after the Attorney General who ordered them), and were jailed or deported after unfair show trials. The IWW and Socialist Party were destroyed as organizations, and the militant labor movement no longer existed.
Elected officials from the Socialist Party were also targeted (Socialist members of state legislatures were removed from office), and even US Congressmen were not immune. In 1917, Victor Berger, who had been elected to Congress in 1910 but lost his re-election, was arrested and charged with violations of the Espionage Act for speaking out against the war. As he was going to trial, Berger ran again for the US Congress, and was elected despite being under indictment for sedition. In response, the US House of Representatives formed a special committee to decide whether to allow Berger to assume office. In November 1919, Congress declared that Berger could not take office, declared his seat vacant, and ordered another election. Berger won that election too, and in January 1920 Congress again declared that Berger could not assume office. Another election was ordered, and this time Berger was narrowly defeated. As all this was going on, Berger’s trial on sedition charges took place—he was convicted and sentenced to 20 years in prison, but his conviction was overturned by the Supreme Court in 1921. In 1922, Berger again ran for US Congress and was elected, serving three terms before being defeated in 1928.