X-Men: Magneto, always referred to as the Big Bad, is the first person the heroes team up with when someone worse comes along.
Particularly in the 90s cartoon, most notably in a season-long storyline in which he and Professor Xavier are stranded together in the Savage Land.
The brilliant X-Men graphic novel God Loves Man Kills was the basis for X2, and thus follows the same plot except that, since the comics have been going on long enough that they didn't feel the need to hammer home his villainy, Magneto doesn't really have a Snap Back the way he does in the movie.
And in God Loves, Man Kills II, released to tie in with X2, the X-Men find themselves teaming up with the villain from the original.
Magneto has worked with the X-Men in multiple story lines, even becoming the leader in one story arc. This is because, for most writers, Magneto isn't as much a bad guy as he is a Well-Intentioned Extremist.
It wasn't just for one arc. In the late 1980s, due to Charles Xavier being absent, a reformed Magneto took over Xavier's School for Gifted Youngsters for something like four years (in real world time). If you were reading X-Men and New Mutants back then, Magneto as the head of the Xavier school felt like a new status quo.
Spider-Man's enemies Venom and Carnage hate each other more than they hate him. Any time Carnage pops up, Venom will call a truce with Spider-Man to go wail on Carnage. This most famously occurred in the storyline Maximum Carnage, which was adapted into a Sega Genesis and Super Nintendo game.
In the oddly-named "Venom vs Carnage" comic, after Carnage produces a new symbiote, he and Venom decide that, in the end, they hate the new symbiote even more than they hate each other (it's implied in Carnage's case that this is part of symbiote biology). The result? Their only teamup. Venom calls it "Temporary. VERY temporary."
Loki is willing to fight on Thor's side pretty much any time Asgard is under attack; his goal is to rule it, after all, and he can't rule it if it's demolished.
Spidey and Doc Ock ended up working together at one point, in order to deal with a new villain (Carlyle) who used Ock's arm technology to build a bank-robbing powersuit. While simply being robbed wouldn't have been enough to put Ock on the side of his mortal enemy, there was also the fact that Carlyle was threatening Ock's former fiancée, known to Spider-Man fans as "Aunt May".
Actually, Aunt May being endangered wasn't really a factor in the fight. It didn't do anything except surprise Doc Ock for a moment and lead to a very funny The Rocky Horror Picture Show joke. Spidey came into the fight late as Doc Ock was already going after Caryle for stealing his tech and trying to kill him.
To Doc's credit, he DID stop a building from collapsing just long enough to allow the innocent civilians to escape at Spidey's prompting. That did nothing to STOP him from letting the building collapse on Spidey, noting "you are not a civilian".
Doc Ock also wasn't happy about the inadvertent team-up, later noting (as he told Spidey the weakness in Caryle's armor), "I am not helping you — I am hurting him." World of difference.
It wasn't even the first time Spidey and Ock teamed up, since they also set aside their differences when Hammerhead kidnapped Aunt May. Spider-Man wanted to rescue Aunt May because she was one of his loved ones (along with the fact that he was Spider-Man after all), while Doc Ock wanted to marry May so he could gain access to a nuclear power plant she had inherited.
In Marvel's Secret Invasion mega-event, the villain mastermind The Hood sends his forces into battle to save the Earth from the Skrulls.
He has his own reasons for this: it helps Norman Osborn in his ploy to take over SHIELD and instigate the Dark Reign.
Actually, it's implied that The Hood had no idea of Osborn's plan, until he called together the Cabal for the first time. The Hood would have let the assembled forces fight the Skrulls, if not for the simple fact that if the Skrulls destroy the Earth, they destroy his business.
This was the driving force behind Watchmen's ending in both the original comic and film adaptation.
Though the enemy in each was completely different.
In the comic book series ElfQuest, when two elf tribes — the Wolfriders and the newly-introduced Go-Backs — join forces to wage war against the trolls of King Guttlekraw, the elves form a grudging alliance with the trolls formerly led by the late King Greymung, who have been enslaved by Guttlekraw, even though Greymung's trolls have been the hated enemies of the Wolfriders ever since betraying them back at the start of the storyline. The Go-Backs, meanwhile, would never have thought of teaming up with trolls of any kind, period... But it's probably only because of this uneasy alliance that Guttlekraw's trolls are defeated.
In the 1970s, two issues of The Brave And The Bold featured Batman teaming up with The Joker to solve a crime. In #111, they worked together to solve the mass murder of an upstanding local family, which someone had sloppily tried to pin on the Joker. In the end, it turned out that the whole thing was an elaborate plot between the Joker and the killer to lure Batman into a Deathtrap. In #191, the Penguin is murdered and it looks like the Joker did it. When Batman catches up to him, he proves that he couldn't have done it. It is eventually revealed that the whole thing was a Faking the Dead by the Penguin, who used it to kidnap a local cardinal.
In the Marvel Transformers comic, Ratchet and Megatron teamed in an early episode to bring down Shockwave. Megatron, naturally enough, tried to betray Ratchet, but Ratchet was prepared.
Several years later, during the "Space Pirates!" story in the UK comic, the Autobots and Decepticons join forces to repel the Quintessons, who are trying to conquer Cybertron before Quintessa explodes. Ultra Magnus and Soundwave even get a Back-to-Back Badasses moment. At the end, Soundwave briefly considers the idea of a lasting peace, but realizes the two factions have come too far to ever resolve their differences.
The Autobots and Decepticons were forced to team up again against the Cybertronian Empire, a faction of hyperevolved Decepticons who had abandoned Cybertron eons ago to create a star-spanning empire of their own. They consider the Autobots and the original Decepticons to be disgusting savages, and eventually returned to destroy their "lesser" brethren.
At the end of Final Crisis, Superman is facing the Female Furies and the Justifiers. Who saves him and reverses the Anti-Life Equation? Lex Luthor and Dr. Sivana.
Lex:"Not a single word, Superman. We'll call this the Historic First Team-Up of the forces of "Good" and the forces of "Bad". And I'll take the credit for the win"
Superman:"Whatever you say, Lex. Whatever you say."
Paperinik (Donald Duck's superhero alter ego) is forced to work together with a notorious time pirate known as The Raider early on in order to save a large part of Duckburg from being destroyed. Later on, they actually find themselves in Enemy Mine situations so often that they build up a strange kind of friendship.
This was hardly the first or the last time that Darkseid pulled one of these. In Crisis on Infinite Earths, for example, he ended up being instrumental in finally defeating the Anti-Monitor (but making it very clear he was only doing it not to help the heroes or anything, but rather to ensure that the Anti-Monitor wouldn't destroy everything).
After the death of the Human Torch, Doctor Doom and Reed Richards have very reluctantly agreed to work together in the Future Foundation. This arrangement was brokered by Reed's genius daughter Valeria who convinced Reed that the FF needed someone as ruthlessly pragmatic as Doom if they were going to save the world. She got Doom on board by promising to help undo the brain damage the Intelligensia inflicted on him in Fall of The Hulks.
Superman and Lex Luthor are in conflict almost all the time, and loathe each other with a vengeance, but they share a near-fanatical adoration for and protectiveness of their home city of Metropolis. This has caused them to put aside their differences, abandon their other objectives, and team up to take down villains bent on destroying their beloved city more than once.
They've even saved the world together more than once. Lex ends up doing almost as much good as he does evil.
In the final issue of Paul Cornell's Knight And Squire, everyone in the British super-community teams up to take down The Joker. The heroes, the anti-heroes, the Harmless Villains and the killers like Death Dinosaur. He's just that much of a threat.
More recently, we've had a non-Freedom Fighters examples, as the Anti-Hero Babylon Rogues teamed up with their rivals the Battle Bird Armada to find their ancestral homeland of Babylon Gardens — ironically, this puts them in opposition to the Freedom Fighters, as the entrance to the Gardens is apparently in their home of New Mobotropolis.
Happens on a massive scale in the Farscape comic book arc "The War for the Uncharted Territories", when essentially all the factions in the Uncharted Territories have to put aside their rivalries and join forces in order to stand the slightest chance of defending against conquest by the Kkore, which up until then has been defeating everyone in Curb-Stomp Battles.
One story-arc in the Captain America comic has Cap teaming up with the Red Skull of all people in order to stop a resurrected Hitler from taking control of the Cosmic Cube. Incidentally, this would lead Cap to being briefly exiled from the United States, since the U.S. government assumed he had turned his back on America by aligning with the Skull.
In an Infinities (a what-if brand) issue of Star Wars, specifically the one taking place during the Mortis Arc of Star Wars: The Clone Wars, of all people, Yoda and Darth Sidious (the latter presumably having revealed his Sith identity to Yoda) had to forge a temporary alliance to stop Anakin Skywalker, who became exceptionally powerful via the Dark Side thanks to the Son. The allegiance did them no good, though, as Anakin effortlessly killed them.
Written long before that, Marvel Star Wars has some examples. In one comic Leia and one single stormtrooper from Alderaan are the only respective survivors of disaster on both sides; the stormtrooper claims to be taking her prisoner but by the time anyone finds them it's not the case anymore. In the World of Fire arc, Luke and Leia and a small party of Imperials team up to try and shut off a lethal planetary security system; here, it starts with the Imperials making a threat-offer, but the head of the group soon feels they're trustworthy and starts getting friendly, while one of his men plans to kill them.
The Three Amigos storyline in Judge Dredd is purely an excuse to team him up with his nemeses, Judge Death and Mean Machine Angel.