In my home country of the Netherlands, the most famous example in recent memory dates back to 2002. Three months before the Dutch national elections, Pim Fortuyn had to step down as top candidate of Leefbaar Nederland over controversial statements on imigration and Islam. He formed his very own Lijst Pim Fortuyn, which promptly became the second-largest party
Is there an American precedent for either Trump or Sanders leaving their respective parties and winning a significant percentage of the popular vote?
Yes there is, Republican president Theodore Roosevelt was the Vice President of McKinley and took over when he was killed by an anarchist. He then won the 1904 elections still as a Republican. When he left office in 1908 he tried to have Taft be his protege and expected that Taft would in essence be Roosevelt but younger. Taft, when he became President began to work as an individual and not as someone completely under Roosevelt's thumb. Roosevelt became annoyed with this and made it abundantly clear that he no longer supported Taft at all. In the 1910 midterms the Republican Party managed to lose control of the House of Representatives and had their control of the Senate much reduced. This made the probability of Taft being reelected much less likely. Roosevelt took this idea and made his mind up that he would save the party and lead it to victory. He then ran against Taft in the primaries and came close but didn't win. He then went to the national convention, fought for the nomination, and then when it became impossible for him to win the nomination, he took his supporters and founded the Progressive or "Bull Moose" Party. In the general election of 1912 he succeeded in splitting the Republican vote, pulling in 4.1 million votes (about 27%) and 88 electoral college votes as compared to Taft who won 3.5 million votes (about 23%) and 8 electoral votes. Their Democratic competitor Woodrow Wilson utterly dominated them winning 6.3 million votes (42%) and an utter landslide of electoral votes with 435.
Source:
Teddy Roosevelt is the most famous example. Teddy, as vice-president, assumed the presidency after the assassination of William McKinley in 1901. American tradition going back to Washington was that presidents should only serve two terms. Pretty much out of the blue, Teddy announces on the night of his re-election after assuming office that he would not seek a "third" term, even though his first term had been merely finishing out McKinley's, and his "second" term was his first elected term. I.E. until he made the announcement, no one was really under the impression that he would be violating precedent if he had run for re-election.
Nonetheless, his hand-picked successor in office, William Howard Taft, wins the Republican nomination and the Presidency in 1908.
Teddy then decides that Taft has in effect betrayed his legacy, and decides that he does, in fact, want to run for office a second time, for a "third" term. As Taft already has the Republican nomination, and Wilson the democratic, Roosevelt founds the "progressive" party, better known as the "Bull Moose Party" because of Teddy's claim that he was "fit as a bull moose!"
The result was that TR split the Republican vote, all but guaranteeing Wilson's victory in 1912, as TR+Taft's totals would have been about 51% of the vote, whereas Wilson only won about 42%. Because of the split, however, Wilson wins in an electoral landslide, with 435 electoral votes to TR's 88 and and Taft's 8.
In addition to Teddy Roosevelt, I suppose you could stretch definitions a bit and say that Lincoln "changed parties" in 1864. Elected in 1860 as a Republican, he ran in 1864 under the "National Union Party" label, but basically that was just a temporary re-branding of the Republican Party enabling him to pick a Democrat, Andrew Johnson, as his running mate. There was no one running under the "Republican" label, and all the state and local Republican parties supported the Lincoln-Johnson ticket.
You might include John Tyler. He was a Democrat (even though the party itself had only existed for just a few years), but was disillusioned by Andrew Jackson. He opposed Jackson's consolidation of federal executive power, which forced him to join the Whig movement in the mid-1830s. By 1836, he was a Whig vice presidential candidate, and was eventually elected as a Whig vice president in 1840.
In 1841, he assumed the presidency upon the death of President Harrison. The Whigs-- who were his own party in name-- controlled Congress. Yet Tyler was really a Democrat at heart. He opposed internal improvements and strong national tariffs, which were basic tenets of Whig politics (so far as you could say there were central tenets). Tyler was actually kicked out of the Whig party within a year of his presidency. Continued clashes with the Whigs led nearly to his impeachment.
In the end, he didn't run for reelection and instead rejoined the Democratic party, endorsing its nominee James Polk (who then won the election).