In Transformers Generation 1 it's not unusual to see the Autobots and Decepticons (or expies of them) joining forces to take on a greater threat. It just takes a very large threat to make them do it. Usually Unicron, but not always.
In "The Insecticon Syndrome", Megatron and Optimus Prime fight together against the out-of-control Insecticons. Watching Optimus grab up Megatron's semi-conscious body and force-fold him into gun mode is interesting.
In "Countdown to Extinction", it's Megatron and Optimus Prime cooperating again to stop Starscream'sDoomsday Device. Watching Optimus worry over the damage Megatron is taking to unbolt the device is fascinating.
In "Nightmare Planet", Springer and Razorclaw team up to slay a dragon. Razorclaw was planning to sit back and watch Springer get killed, but a princess bribed him with gold and pointed out that the dragon would most likely kill everybody.
In Transformers Animated, during the second season finale, the Autobots and Decepticons' latest battle is interrupted by Starscream and his clones. The Autobots and Decepticons end up fighting the same enemy, and at one point Optimus and Megatron have a Back-to-Back Badasses moment... only for Megatron to grab Optimus and use him as a living shield. The clones eventually turn on Starscream later, join Megatron, and everyone is back to square one.
In Beast Machines, the Maximals join forces with the surviving Vehicons to survive when Savage appears.
Earlier, in Beast Wars, this happened a ton between the Maximals and the Predacons, always during story arcs where the Vok, the godlike beings using Earth as their own Petri dish, become active again. For example:
The entire final arc of the first season kicks off with Megatron attempting to form a truce with the Maximals when it becomes apparent that the Vok are a much greater threat to both of them than each other.
In season two, when an alien ship appears that put Tigatron and Airazor on a long bus ride, the two factions team up to try to break into it, but all bets are off when Megatron gets control of the ship and all its power. Though Tarantulas does team up with the maximals in order to prevent Megatron from using the Vok technology to leave Earth.
Transformers Armada is technically an anime, but whatever. In any case, its very title refers to the Autobot-Decepticon alliance formed in the final episodes to combat Unicron.
Transformers Prime. The Autobots temporarily team up with Megatron to stop Unicron from awakening.
Justice League, "The Return". Lex Luthor is forced to work with the League to stop AMAZO, an android he himself had loosed on them in an earlier episode, from killing him. This applies to the League more, as AMAZO isn't out to do anything else not in his way (he moved Oa to another dimension because it was easier than fighting, and fought back against the League because they attacked him), but he is after Luthor, who deceived and manipulated him. The League figures that the android will kill Luthor (at this moment in the series, in a Heel-Face Turn), so THEY decide to help HIM. Part of it was because it was personal to GL John Stewart, as they didn't know he just moved Oa. They saw him approach the planet, give off a flash, and then it was gone.
Luthor and the entire Legion of Doom were forced to help the Justice League defend Earth from invasion by Apokolips.Luthor was the one who did Darkseid in. It was a collective decision of "the only one allowed to take over the planet".
Wonder Woman and Hades against Felix Faust although this wasn't by choice. She was ordered to reinstate Hades by the Gods, and when she still had some reluctance, it ended when Hermes pointed out how Faust was indirectly harming Wonder Woman's magical friends by usurping Hades' post.
The episode with the Justice Lords. Luthor hilariously teams up with Good Superman just for the pleasure of zapping a Superman, any Superman, with a Kryptonite laser gun.
Good Superman: Go for it.
Luthor: Oh yes.
In Code Lyoko episode "Marabounta", Jérémie's newest attempt to destroy XANA goes haywire and threatens to destroy Lyoko itself. XANA sends monsters to help the good guys destroy the threat. When the combined team is victorious, the heroes expect the monsters to immediately turn on them. Instead, the monsters bow and then leave without incident. (Jérémie does warn everybody that this truce was clearly temporary.)
In the following episode, "Common Interest", Jérémie and XANA team up to save Lyoko and Aelita when the uranium battery that powers the Supercomputer starts dying. This time however, XANA does strike back immediately after the teamwork is through.
In the animated TV show of The Neverending Story, the main character teams up with the evil female character, who even saves him at one point.
In "The Chase", the gang inadvertently work with Zuko and Iroh to corner Azula. This gets broken when Azula attacks Iroh while he's distracted.
When Zuko has a Heel-Face Turn and joins the Gaang. Included here because, while Zuko truly wants to switch sides, the Gaang (especially Katara) still views him as an enemy for some time. Nevertheless, although the only reason the Gaang agree to join up with him is because Aang needs a firebending teacher, the two of them eventually decide to put their differences aside when they discover that they have more in common than they think, so it's not long before they're working smoothly together to take down the Big Bad, becoming literal Fire-Forged Friends in the process.
Iroh asks for the Gaang's help to save Zuko, while the Gaang needs help to save Katara. This is a very mild example since Iroh was practically on friendly terms with Toph already and Iroh was never that much of an enemy in any meaning of the word, but Aang and Sokka are suspicious at first.
Darkwing Duck once teamed up with electrical supervillain Megavolt against an enemy that threatened to destroy St. Canard. When Gosalyn asks Megavolt why he's helping out, he explains that if the Big Bad destroyed the city, there'd be nothing left for him to rob.
And Megavolt did so again, along with Fearsome Five teammates Bushroot, Liquidator, and Quacker Jack, when team leader Negaduck steals their powers with a magical gem. (Quacker Jack had no power to steal, other than his wackiness. That's your cue, fellow tropers!)
The four of them did it the second time the Fearsome Five worked as a team, again after Negaduck double-crossed them. (Apparently, they didn't learn the first time.)
And Megavolt teamed up with Darkwing again in order to stop the Gosalyn-shaped representations of radio, light, and heat waves from wreaking havoc upon the city. His excuse for the team up this time? The physical representations of the electromagnetic spectrum hurt his feelings. (Darkwing was willing to work with him because he was an expert in the field - well, the best one that was available, at least.)
Also, Darkwing Duck teamed up with Ineffectual Sympathetic Villain Bushroot a few times, most notably against an invasion of evil cabbages from outer space.
Bushroot: "Hey, I may be a mutant plant-duck, sure, but I'm an Earth mutant plant-duck!"
And Quackerjack in "The Haunting of Mr. Banana Brain", when Paddywack possessed Mr. Banana Brain. (That guy just wasn't funny.)
Robin must reluctantly team up with Slade to save Raven in Teen Titans. Slade uses this time trying to annoy Robin as much as possible, naturally. Later Slade helps them out with Trigon with his extremely badass antler cutting fiery ax. (He didn't have to come back, but he wanted to, because as he put it, "I'm nobody's servant.")
Also the Titans team up with Gizmo to rescue Cyborg. Actually, Gizmo has no choice in the matter as Raven threatens to turn into some demon-monster and devour him if he doesn't. (Robin figured that Gizmo was the only one who was knowledgable enough to repair Cyborg, although a lot of fans did remember Fixit and thought that he might have been a better choice...)
Robin also teams up with Red X in "X" to stop the theft of a dangerous substance. While the last time we saw Red X, he was Robin in disguise this time the the Red X suit was stolen by an unknown person.)
A similar plotline occurred in The Batman, when the villainous residents of Arkham Asylum, freed by an alien invasion, join the fight against the aliens, with the Joker angrily stating that causing mayhem in Gotham is his job. He goes so far as to gleefully proclaim that the whole world has gone mad after seeing Gordon and Freeze protect each other's backs.
Despite his declaration of "just this once" (quote at top of main page), Zim and Dib of Invader Zim have teamed up at least three times against various crises.
Notable episodes: "Bolognius Maximus", "Hamstergeddon", "Halloween Spectacular of Spooky Doom", and "Tak: The Hideous New Girl".
Subverted in "Planet Jackers": Zim reluctantly tries to form an alliance with Dib, as he requires Dib's telescope (Zim's has been broken). Dib refuses to believe Zim has (somewhat) good intentions and kicks Zim out of his house without allowing time for an explanation.
Lampshaded in "Walk for Your Lives": Zim forces an alliance on Dib, who is the only way to stop a massive slow-motion explosion. Dib (who's also in slow-motion) gets fired out of a cannon into an explosion, causing it to speed back up and finish already. But it's still an alliance.
Not really. If being captured counts as being an ally, was Dib helping Zim destroy the world in "Future Dib"? He vehemently objected to the plan, and it's not like Zim flung him at the explosion for anyone's benefit but his own.
There was Operation: M.U.N.C.H.I.E.S. After Sector V spent the whole story fighting nearly ever villain in the series over the last box of cereal in a supermarket, Knightbrace grabs it, but intends to destroy it, not eat it. So the heroes call a truce with the other villains to get from him. (And then all of them are able to share it at the end, making it a happy ending for everyone except Knightbrace.)
Danny and his ghost hunting rival/enemy Valerie work together to outdo Skulker once they stop trying to torment one another. Being handcuffed together didn't help matters.
In the first movie, "Reign Storm", Danny, Vlad, and Valerie had to team up to try and take down the much greater threat that was Pariah Dark. In fact every enemy ghost came to help out during the final battle.
Skulker: Now, go! Defeat him, so I will be free to hunt you another day!
Danny: (to Ember) Guy really knows how to motivate you...
Danny teamed up with the rest of his foes to break out of Walker's prison in "Prisoners of Love."
Danny and every single ghost in existence teaming up to turn the Earth intangible in "Phantom Planet." Wow, he does do this a lot!
In the Christmas Episode, when the Ghostwriter tried to teach Danny a lesson, all other ghosts Danny met in the episode agreed to help him because the Ghostwriter broke the Christmas truce.
In "Livin' Large", the Guys in White tried to blow up the Ghost Zone, unaware that it'd destroy Earth as well, and Danny teamed up with some of his ghostly enemies to stop them.
Danny and Valerie teamed up again in "D-Stabilized" to defeat Vlad and save Dani. Bonus points for Valerie discovering Vlad's secret identity at the end!
The Raccoons episode "The Intruders" has the bad guy Cyril Sneer working together with the titular raccoons and their friends in order to save his own son and one of the raccoons who got trapped in his supersafe vault.
In The Pirates of Dark Water episode "The Game Players of Undar", frog-like creatures effortlessly capture both the main hero and the main villain, handcuff them together, and force them to work together to win a dangerous game on an island for their own amusement.
In the episode "Game Over For Owlman", Batman is forced to team up with his arch nemesis, The Joker after the rest of the heroes of the series become convinced he has become a bad guy thanks to the machinations of his Evil Twin Owlman.
And again with Two-Face in the beginning of "The Fate of Equinox", after his hired henchmen go against his decision to spare Batman.
Commander X-2 did this with Duck Dodgers and his Cadet on occasion — especially when his Queen was in direct danger. Awwwww.
An episode of The Powerpuff Girls had them needing Mojo Jojo's help to beat this huge alien thing that was so evil even Mojo considered it his superior.
In an episode of Adventures of the Gummi Bears ("Just a tad smarter"), Toadie's cousin Tadpole takes over Castle Drekmore, kicks Duke Igthorn out, and orders the ogres to destroy all the gummiberry bushes. Neither Igthorn nor the Gummis want the bushes destroyed, so they reluctantly team up to get rid of Tadpole.
In another episode("For a few sovereigns more"), Duke Igthorn hires a bounty hunter to catch a Gummi Bear. When the hunter returns with Cubbi Gummi but Igthorn refuses to pay, he and Cubbi are tossed into a dungeon cell, and have to work together to escape. That episode was a Chained Heat, as well.
In the "Wishology" trilogy, all of Timmy's friends and allies except for Mark are captured. Needing help, he recruits Vicky, Crocker, and Dark Laser to battle the Darkness. He needs to offer them something: 20 dollars, a look at his fairies, and an opportunity to destroy him when it's over, respectively.
Happened several times on Gargoyles. David Xanatos is such a Magnificent Bastard that the Manhattan Clan always suspected they were being used. Occasionally they were wrong.
Bart and Lisa from The Simpsons teamed up with Sideshow Bob in "Brother From Another Series" to stop Bob's brother, Cecil, from blowing up the Springfield Dam to destroy the evidence that he cut back on construction to embezzle funds.
While not quite an enemy mine per se, they also had some help from Sideshow Bob in identifying the real culprit of Homer's kidnapping in "Wedding for Disaster" it was Patty and Selma Bouvier, the latter of whom was ironically a former near-victim of Sideshow Bob.
This became the first of a couple of Enemy Mines Obi-Wan had against Maul. In Season 5 he teams up with the pirate Hondo Ohnaka (although his status as an enemy is debatable), and then later the Death Watch member Bo-Katan, who had gone against Maul's take-over of the Death Watch and Mandalore. Bo-Katan even Lampshades this when she does an earlier Enemy Mine with her sister, Satine.
Bo-Katan: The enemy of my enemy is my friend.
Ahsoka and a couple of Jedi younglings also teamed up with Hondo and his pirates in order to fight General Grievous and escape Florrum.
In the anti-drug episode of G.I. Joe, the Joes and the Cobras recognize a common enemy in the drug kingpin Headman and enter an awkward alliance to take him out.
They also team up against "The Gamesmaster" after he captures members from both sides.
Buzz Lightyear and the Evil Emperor Zurg work together to beat aliens that intend to conquer the entire galaxy, including Zurg's home, in an episode of Buzz Lightyear of Star Command.
In the W.I.T.C.H. season two episode "W is for Witch", Will decides to recruit season one Big Bad Prince Phobos and his crony Cedric in subduing Nerissa. The end result? The start of a Gambit Pileup that doesn't end until the series finale!
Winx Club got in on this as well. Season 1 saw the Cloud Tower student witches moving in with the fairies at Alfea to fight the Trix, and one of the major complaints about this arc is that they're nowhere to be seen during the battles. Season 2 features this trope again at CT, and although Musa and Layla are briefly shown fighting the Trix together with the student witches, they're again nowhere to be seen afterwards. Although the events of S1 haven't been completely forgotten by the time of the S2 arc note in the original at least, as the Winx specifically mention this while heading to CT, the witches still dread teaming up with the fairies.
There's also the episode with Evil Seed, a plant monster who appears and starts beating down heroes and villains alike. He-Man, The Sorceress, and after much reluctance, Skeletor team up to take the guy down.
One episode of She-Ra: Princess of Power featured She-Ra and Hordak accidentally sent to another dimension and having to join forces to return.
The fifth season of the 2003 Teenage Mutant Ninja Turtles series features the Turtles (along with the Ninja Tribunal's human accolades and the Justice Force) teaming up with Karai, Hun, and Bishop to fight the Tengu Shredder.
During the "Return to New York" arc in season 1, when Baxter Stockman betrayed the Shredder and attacked both him and the Turtles, threatening everyone. The Turtles and Shredder briefly join forces to defeat him before resuming their battle.
Happened in the 80's cartoon as well. When the "Killer Pizza" monsters go berserk, the Turtles and Shredder have to team up to keep the creatures from killing all of them. It's even given a lampshade by Leonardo and Donatello.
Also happens in the "Turtles Forever" film. Krang and '87 Shredder join forces with the '87 and '03 Turtles at the end to stop the Utrom Shredder from destroying the multiverse.
There were previous instances of Kim and Shego joining forces against a common enemy: Kim enlisted Shego's help against an old Team Go enemy in "Go Team Go", and Shego stopped Drakken's new sidekick from beating Kim in "Mad Dogs and Aliens".
ReBoot does this in its second season finale. Bob is forced to team up with Megabyte and Hexadecimal to stop the Web from destroying Mainframe. However Megabyte, being the Magnificent Bastard that he is, takes advantage of the situation to betray Bob and strand him in the Web.
However, an earlier episode has Megabyte actually honoring his commitment. Megabyte's goons steal game energy in an attempt to break into the Archives. Unfortunately for Megabyte, he gets trapped in the game that they steal the energy from. When the User loads a new game and it collides with the current one, Megabyte gets trapped sinking into quicksand while being shot at by a T-Rex with a machine gun. After begging Bob for help, Bob decides to save him. Later in the same episode, Megabyte kidnaps Enzo. After the gateway command is he stole is destroyed, Bob reminds him how he saved him in the game he lets Bob save Enzo without a fight. As they're leaving, Megabyte says, "Now we're even, guardian. Now we're even."
The main plot of Mulan II required the protagonists, under the Emperor's orders, to travel over to Qui-Gong to forge an alliance with the kingdom in what is essentially an enemy mine gambit to defend China from the Mongolians' imminent invasion.
The 90s X-Men animated series did this with every appearance of Magneto after his introduction. Every.Single.Appearance. Except for one time when he helped Apocalypse capture a psychic-empowered mutant for his master plan. It got to the point where, during the Grand Finale, he was considered an honorary X-Man, and shown as part of the team in the final shot of the series.
In the X-Men: Evolution episode "Survival of the Fittest" they worked with the Brotherhood to stop The Juggernaut. Then at the end of season 2 the X-Men and Brotherhood teamed up against first Magneto's team and then the Sentinel. The arc plot for season 3 involved everyone trying to stop the unsealing of Apocalypse, and season 4 ended with Apocalypse and his four mind-controlled Horsemen against the X-Men, the Brotherhood, Magneto's team, and the now-SHIELD-controlled Sentinels.
In The Spectacular Spider-Man, Spidey made a temporary alliance with the Rhino to destroy a specs program which gave the owner the instructions on how to make more Rhino-armored supervillains. The original Rhino wasn't too happy about that, so after battling Hammerhead and Silver Sable for it, Spidey offered a team-up. After it was destroyed, however, things went back to normal...
Another variation had Meg and Connie team up to make take down a newly-popular Chris.
Megas XLR did this when Coop and Gorath got trapped in a Mirror Universe and were captured by Mirror Jamie. Then Mirror Jamie joins the Enemy Mine when Mirror Coop shows up to kick their asses. This one almost became permanent after Coop and Gorath succeed in defeating Mirror Coop, but then Megas trips and ends up destroying Gorath's entire army. That ends the team-up.
The New Adventures of Superman episode "Luminians on the Loose". After Lex Luthor brings the title creatures to Earth, they turn on him and try to kill him. Luthor is forced to team up with Superman to defeat them.
In "It's A Jersey Thing" Randy decides to turn to Al Qaeda for help.
Randy: Our country's getting back to normal, and we owe it all to Osama bin Laden. On this day let us all remember that no people on this earth are really enemies, only folks with differences.
[Paratrooper shoots Bin Laden].
In "Goth Kids 3: Dawn of the Poseurs" the Goths and their sworn enemies, the Vampire kids, team up to defend the world from their greatest foe: emos.
Hurricanes episode "Target: Winston" had Winston Honeychurch fearing for his life. Amanda Carey had, at first, believed Stavros Garkos, the series' main villain, was behind this and, along with Stats, went to his hotel room to spy on him but were caught. Wanting to know what Amanda was up to when she accused him, the this time innocent Garkos told his main thugs, Wyn and Genghis, to help her.
Xiaolin Showdown has the Card-Carrying Villain Jack Spicer save the Xiaolin monks from the re-humanized evil sorceress Wuya. He then explains that he's willing to provide any help they need in order to defeat Wuya, since he sees her as a threat to his own plans of world domination.
In the episode "Dangerous Minds" of season 2, Jack ends up accidentally freeing ancient spider creatures that are described as "neither good nor evil, they are simply consumers". They will literally eat everything, the world itself until there is nothing left. The villains don't like this as they want to rule the world not destroy it. Omi and Chase Young team up to stop the spiders and save the world. Chase even uses this as part of his plan to convince Omi to join his side.
Batman: The Animated Series had an episode called "The Trial", which featured the city's new District Attorney blaming Batman for all the superpowered criminals in Gotham City. This eventually leads to the DA being kidnapped by the villains and Batman being captured while trying to rescue her. The villains then put Batman on trial for ruining their lives and turning them into criminals, and they make the DA serve as Batman's defense lawyer. The DA demolishes the villains' claims one by one, pointing out that they were all responsible for their own problems and would have become villains anyway; the only thing Batman really influenced them to do was wear costumes. The villains are forced to acquit Batman, but they decide to kill him and the DA anyway For the Evulz. Now that the DA has done her job, it's time for Batman to do his...
Then their was the episode "Harlinquinade", where Batman recruited Harley Quinn's help to find the Joker when he stole a nuclear weapon (offering her parole as an incentive). Harley didn't quite manage to stand up to Mistuh Jay in this episode, but she came close. (She would eventually, later.)
Defied in The Dreamstone episode "The Statue Collection", when both sides get stranded on a desert island and Sgt Blob and Albert are antagonised by a sea monster, Frizz and Nug quickly assemble a war device to fend it off. Rufus and Amberley, convinced it's doing more harm than good (and likely still pissed about them turning Pildit into stone) knock the two out, leaving Albert to take care of the monster by himself.
Played more straight in "The Dark Side", after the Urpneys capture the heroes, they are attacked by another monster. The Dream Maker negotiates with it in return for the Urpneys releasing them.
Another light example happens in "Return Of The Nightmare Stone" where Urpgor, after being rendered redundant by Zordrak's new stone, advises the Noops to throw it into the Bottomless Pit.
Shere Khan assisted Baloo in a few TaleSpin episodes. Also in "Stuck On You" where Don Karnage must make a truce with Baloo when they are accidentally glued to each other (and his crew create a mutiny).
The Troublesome Trucks from Thomas the Tank Engine are known to play tricks on the engines from being the cause of their accidents to mercilessly make up jokes and songs about them, but they are times where they and the engines can be on the same side when dealing with a common foe. In "Special Attraction", they helped Percy deal with a disagreeable boat named Bulstrode and in "The World's Strongest Engine" when Thomas and Percy lampshaded at the end of said episode that they've learned that even troublesome trucks can do an engine a favor, especially if it's getting rid of an prejudiced, arrogant Diesel.
The Diesel have always had a heated rivalry with "steamies", though there are times even the most prejudiced of both kind have ended up teaming up to solve a dilemma. This is the entire plot of "Calling All Engines" where both must work together to build Sodor's airport, which culminates in Thomas even having to get Diesel 10 for help.
Sponge Bob Square Pants: Mr. Krabs and Plankton have teamed up on a number of occasions. The most notable being "Best Frenemies", where the two try to take down a restaurant more successful than either of theirs.
Another example is "Eeek, an Urchin!", where Plankton helps the Krusty Krab crew settle a sea urchin infestation, because "he can't steal the formula with vermin running around".
Recess had at least two instances where Randall ends up forging a truce.
Not to mention the movie where Randall, Miss Finster and Principal Prickley team up with the kids against a villain that wants to create eternal winter
In Motorcity, "Red" resents Mike Chilton for leading the group that destroyed the home he supposedly lived in. He ends up joining forces with Kane for this reason, despite the fact it was really Kane who is responsible for the destruction of his Motorcity home.
In Street Fighter episode "Strange Bedfellows" (for those who don't know, it's a former name of this trope), Guile and Bison teamed up against Akuma.
Several Tom and Jerry cartoons have the titular cat and mouse teaming up to get rid of an enemy, such as Dog Trouble, Old Rockin' Chair Tom and Triplet Trouble.