Happens regularly in soap operas. For example, on All My Children, lifetime enemies Adam and Palmer teamed up to kill a rapist.
24: Season 2, Jack is forced to work with Nina Myers, the woman who killed his wife, in order to find information on the season's terrorist threat. Likewise, in season 6, Jack teams up with the previous season's Big BadCharles Logan to investigate a corrupt Russian diplomat.
Season 5 has him team up with Christopher Henderson to stop bigger threat Vladimir Bierko.
The 4400: An unusual example occurs where Jordan Collier and Tom Baldwin must work together to escape a dream sequence (whose actual purpose is to get people to work together). It's an odd example in that neither character is a villain: as Tom is a government official doing its best to deal with bizarre circumstances (and sometimes engaging in some morally-questionable methods of dealing with problems) and Jordan Collier is trying to avert the end of civilization, but supports anarchy and believes everyone should take Promicin (a drug that has a 50% chance of death or super-powers).
American Gothic: Buck, Dr. Crower, Gail, and Ben are all forced to work together in the episode "The Beast Within", when Ben's deranged brother takes them all hostage: Dr. Matt's hand is hurt so he has to coach Ben in performing an emergency surgery, while Buck and Gail have to work together to find the lost key to the handcuffs holding them and Caleb prisoner. (The fact this all turns out to be The Plan orchestrated by Buck rather subverts the trope.)
And at the very end of the series, Merlyn is forced to go to Dr. Peele, Selena, and Ben for aid in digging up Buck's 'corpse' so that the two of them can then work together to save Gail and stop Caleb's rampage.
American Horror Story: Murder House: Constance forms an alliance with Moira, the ghost of the woman she murdered, to dispose of a sleazy developer who plans to tear down the house.
Angel: Subverted Trope during the fourth season, when Angel comes to Lilah for information on the Beast and suggests they work together:
Angel: You're afraid of what's coming. Maybe we can help each other. The enemy of my enemy— Lilah: Can kiss my ass too.
However, Angel eventually convinces Lilah to give him the information he was seeking, with the argument that Angel will either use it to stop The Beast (in which case Lilah wins) or Angel will die trying (in which case Lilah also wins). As it turns out he decided to Take a Third Option, so in the end it's more played straight.
And in the end, she does ally with the team anyways.
Despite his mistrust and dislike of him, Detective Lance asks for the Arrow's help on multiple occasions. By Season 2, this has evolved into them having formed an understanding, and Lance being a Friend on the Force.
Another episode has a scene deliberately written in defiance of the trope, which Straczynski hates. Mortal enemies Londo and G'Kar are trapped in an elevator with a fire outside draining their oxygen. Londo declares that they'll have to work together to escape but G'Kar refuses: he's perfectly fine with dying as long as he gets to see Londo die, too.
G'kar: (...)But I don't have to kill you. I don't have to do anything! And I still get to watch you die! I find this most appealing! Londo: This is insane! We must work together! G'Kar: ... No. As the humans say: "Up yours, die." *Continues giggling*
The irony of this is that, if the Narn surrender treaty didn't include such harsh penalties for G'Kar just killing Londo, he might happily have helped. However, thanks to the excessive measures taken to prevent Narns attacking Centauri, this was the only way G'Kar would ever get to see Londo die.
Londo and G'Kar team up again in the "And The Rock Cried Out, 'No Hiding Place'" when Londo constructs a Batman Gambit to enlist G'Kar's aid in destroying Lord Refa, whom Londo believes killed his lover Adira and was responsible for using mass projectors on the Narn homeworld. Londo supposedly tricks G'Kar into leaving the sanctuary of station under the pretext of having the Centauri forces arrest him on Narn in Refa's presence; in fact, it was so G'Kar could make contact with the Narn resistance and set up the No-Holds-Barred Beatdown Lord Refa receives to the tune of the episode's eponymous Gospel tune.
Bester invokes the saying "the enemy of my enemy is my friend" in persuading Sheridan to work with him against the Shadows, whom Bester has also come to mistrust, in "Ship of Tears".
Battlestar Galactica (Reimagined): Has this quite a few times as well, usually involving Cylons and humans co-operating, such as Athena's Heel-Face Turn and the rebel Cylon faction seeking Galactica's help against Brother Cavil. However the "enemy of my enemy is my friend" quote is actually used by President Roslin when she teams up with terrorist-turned-radical politician Tom Zarek, after Commander Adama tries to force her resignation.
Breaking Bad: Hector Salamanca hates Walter White and would like nothing more than to kill him. However, Walter knows that Hector hates his mutual enemy, Gustavo 'Gus' Fring, even more and gives him a chance for revenge. Through an impressive Batman Gambit, they lure Gus Fring, who has his own vendetta against Hector, to Hector's nursing home. Hector proceeds to ding his bell one last time to detonate a bomb Walter planted on his wheelchair to take both himself and Gus Fring out.
Buffy teamed up with Spike to stop Angelus at the end of season 2. With some unusual fallout; because the main time she'd met him had been during this Enemy Mine situation, when Spike returned in season 3, Joyce thought that they were actually allies and let him in. In season four he also teamed up with them a few times for various reasons (once because Giles just paid him to), and by the fifth he ran out of a need for outside excuses and turned into a straight ally.
Season 8 had Dracula team up with the Scoobies, who he hates (except Xander), for vengeance as the villains (Japanese vampires and a witch) had taken his power. Also, because he was kind of a racist.
In "Prophecy Girl", Xander enlists his hated enemy's (Angel) help to storm the Master's lair, and save Buffy. Angel scoffs at that, so Xander shoves a cross in his face for extra convincing.
A very brief one occurs in Season 3's "Choices," when the Mayor and Faith, in the interest of mutual survival, team up with the Scooby Gang in the high school cafeteria when demon spiders escape from the Box of Gavrok.
They tease this with The Master and Buffy in Season 8, but it never actually happens, unless you count him trying to sneak attack Twilight while he and Buffy are fighting.
The General very reluctantly works with the Slayers to fight the invading demon armies.
Castle: In the season 5 finale, Beckett uncovers a murder she initially believes was the work of Senator Bracken, the man who hired a hitman to kill her mother. She then uncovers that it was actually the work of a hitman setting up to snipe Bracken in two days, and is now forced to work with him on the investigation of an attempted murder of a man she would like nothing less than to kill herself. The irony is not lost on her.
Charmed: This happens several times when the Halliwell sisters must reluctantly team up with demons for various reasons that are in the best interests of both sides, such as preventing the existence of magic from being revealed to the mostly unaware human population or stopping a neutral third party whose plan, if successful, would result in the vast majority of combatants on both sides being exterminated.
A strange case of this happens in Season 6's two-part season finale where that season's Big Bad, corrupt Elder Gideon, teams up with his evil Mirror Universe counterpart to trap two of the sisters in the Mirror Universe where they team up with that universe's version of their most notorious recurring enemy, the demon Barbas (since demons are the good guys in that universe) before fighting and then teaming up with their own evil counterparts in order to return to their own universe. Unfortunately, that causes the two universes to become unbalanced resulting in the normal universe becoming too good and the mirror universe becoming too evil, which forces the sisters to once again team up with their evil counterparts to restore the balance between both universes by killing both versions of Gideon, who have each meanwhile teamed up with their own universe's version of Barbas. In short, the entire episode is a confusing mess of various Enemy Mine scenarios.
Community has a really bizarre example in the episode "G.I. Jeff". Jeff falls into a coma and dreams he's a member of G.I. Joe. After a series of mishaps, he finds himself on the run from the unit with the other study group members (also imagined as G.I. Joe members). Eventually, he causes so much trouble, G.I. Joe and Cobra have to join forces to capture him.
The serial "Logopolis". Of course, the Master turns on the Doctor, tries to destroy the Universe rather than being unable to rule it, and then kills the Doctor by shaking him off a radio telescope into a parking lot. It isn't the end though, as the moment has been prepared for. Considering how the Master is just about the closest thing the Doctor has to a rival, they've certainly been forced to team up on any number of occasions throughout their history — usually to stop a catastrophic evil that the Master himself unleashed, and invariably with the Master turning on the Doctor shortly before or after the problem is solved. Of course, the Doctor has been anticipating betrayal all along, and has almost certainly done something clever to come out ahead regardless.
Happens in the conclusion of "Trial of a Time Lord", when the Master reveals that the prosecutor, the Valeyard, is actually the Doctor's Enemy Without, whom will get the Doctor's remaining regenerations if he gets the Doctor executed. The Master helps the Doctor for two reasons: to have an enemy with which he's more familiar (the Doctor vs. the Valeyard) and to retain the chance to end the Doctor's existence personally.
In "Doomsday", the presence of just four Daleks bumps an entire army of Cybermen down from "enemy" to "temporary ally". Once the Daleks start moving, Torchwood and the Cybermen appear to ignore each other in favour of the new targets.
In "A Good Man Goes to War", the Doctor calls upon the aid of the Silurians, Judoon and a lone dishonored Sontaran alongside actual friends to rescue Amy. However, the Silurians and Sontaran's reasons for teaming up isn't so much the presence of a common enemy as it is the fact that they owe the Doctor a debt.
In "Genesis of the Daleks" when the Doctor has the chance to destroy the Daleks at their creation, one of the reasons he gives against this is that otherwise hostile races would be forced into alliances due to this.
Comes close to happening in "The Time of the Doctor", where, like in "The Pandorica Opens", various races gather round the planet Trenzalore to restart the Time War if the Time Lords return. However much of this war is unseen and slightly subverted in that everybody is reluctant to start the war. It finally becomes Enemy Mine when on the other side, the Doctor and the Papal Mainframe, including the Silents, fight together.
Apparently what happened after "Frontier in Space", where the Master and Daleks tried to cause a war between Earth and Draconia after which they would invade the Galaxy. The humans and Draconians are told by the Doctor to form an alliance against the Daleks.
Played straight in the "Liars, Guns, and Money" trilogy when Moya's crew recruit various aliens who had tried to kill them in the past to help them pull off a heist.
Played straight and subverted with John and Scorpius multiple times as John pretends to team up with Scorpius, then John is forced to team up with Scorpius to save Aeryn (twice!), then it looks like Scorpius has betrayed them but he really hasn't, then John betrays Scorpius only to have to go back and save him again. And then they end up teaming up with Scorpius again for the miniseries, still against John's better judgment.
Firefly: Does this in the episode "Trash", where the crew joins up on a heist with Saffron, the psychotic seductress who tried to steal their ship a few episodes back. Rather amusingly subverted: Saffron unsurprisingly double-crosses the crew, and the crew turns on her in return, having fully expected her sudden but inevitable betrayal.
Game of Thrones: This is the reason the Wildlings are all united under a single leader. Every tribe hates each others' guts: they just hate the idea of dying in droves to the White Walkers more.
Get Smart: In one episode, Max Smart from CONTROL and Siegfried from KAOS team up against a man conspiring to destroy the world, since if he succeeded they would have nothing to fight about and would be out of a job.
Heroes: This is the favorite way they deals with Sylar.
Volume 3 had Noah Bennet work with Sylar to stop the escaped Level 5 villains. The two barely tolerated each other but seem to have bonded by the end of the 3rd episode. Then Sylar starts up with the brain-stealing again, causing Bennet to vow to kill him eventually.
What Noah meant could very likely refer to taming Sylar. In Season 3, Episode 4, "I am Become Death", Peter is taken to a future timeline by his future self. In this timeline, Peter discovers a calm and collected Sylar, living in the Bennet household with a son named Noah.
Also, in the Volume 3 finale, Bennet frees all the Level 5 supervillains so they can help fight Sylar, who's on the downswing of his Heel-Face Revolving Door trend. They all last maybe 3 minutes, tops.
Volume 5 does this again when Peter realizes that in order to prevent Samuel Sullivan's plans from coming into fruition, he's going to need Sylar's help. Unfortunately, it meant getting himself stuck inside Sylar's head and dealing with the latter's Villainous BSOD. Unlike the many times before, though, it works; the two save the day, and Sylar's Heel-Face Turn seems to stick this time.
Kamen Rider Decade: In the final arc, the separate Kamen Rider worlds are pitted against each other in a giant war, with the losers being erased from existence, so naturally Riders and Kaijin put aside their differences in order to protect their universes. Tsukasa, in the meantime, tries to convince everyone to focus on the common enemy in Daishocker; it works almost too late, but then the death of Apollo Geist actually accelerates the destruction rather than stopping it. Dammit.
Also in "The Last Dam Job", the team brings in a few people who have been enemies in the past. Eliot and Quinn, in particular, have a perfectly amicable working relationship despite the fact that they tried to beat one another to death in the Season 1 finale.
LOST: Has done several times, both in regards to the survivors and the Others.
In Season 3, when Kate and Juliet are handcuffed together and forced to work together to escape the smoke monster's repeated attacks. It turns out Juliet herself handcuffed them together to try and gain Kate's trust.
Throughout the second half of Season 4, Ben joins forces with Locke's group to fight the freighter mercenaries.
At the end of Season 4, Kate and Sayid team up with Richard and his army of Others to rescue Ben from the mercenaries.
Then there is the reluctant team-up between Losties and the Others of 1977 in the Season 5 finale.
Finally, Season 6 had everyone teaming up against the new Big Bad. Ben Linus and Charles Widmore sure were surprised to find themselves working toward a common goal!
The Man from U.N.C.L.E.: Had this trope as part of its central premise, as THRUSH forces the Western nations and their ideological opponents the Soviet Union to cooperate in forming UNCLE.
M*A*S*H: Charles Winchester, ordinarily a foil to Hawkeye and B.J., will occasionally join forces with one of them against the other (usually as part of an Escalating War), or with both of them against a common target. The latter moments tend to highlight Winchester's Jerk with a Heart of Gold qualities, given that the people he targets are always bullies themselves, such as a racist colonel, or a man bigoted against stutterers, or the insanely jingoistic Colonel Flagg.
Flagg's mistake was trying to blackmail Charles into helping him with a threat of prison. Charles doesn't like being manipulated in that way, and knows precisely how to deal with it (he tricks Flagg into trying to arrest Colonel Potter, and the Mayor and police chief of Ouijonbou, all three of whom have the right contact to get rid of Flagg for good now that they have something solid against him).
One good example is the episode where Hot Lips is being accused of being a communist by a congressional aide. Without even being asked, Winchester takes a stand against the aide and takes up for Margaret.
Due to a misunderstanding and accident of timing, the Colonel who sent Charles to the 4077th attacks Margaret (thinking she's the woman Charles procured for his entertainment). The Colonel offers to transfer Charles back to Tokyo, and all he has to do is lie about what happened with Margaret. Charles is clearly tormented by the decision, but chooses to tell the truth as he cannot stand to destroy Margaret's career for his own (relatively modest) gain.
Merlin1998: Merlin himself outright states that this is his motivation for allying himself to Uther. Uther's enemy, Vortigern, is Merlin's enemy and has joined forces with an even worse enemy.
Naturally Sadie: While not as big of enemies as most of the other examples, this show uses this a lot to get characters who dislike one of the main cast to work alongside them, usually for a school project. One memorable incident has almost the entire teenage cast working together in detention while the remaining member teams up with Mallcop — two examples in one episode, there are many more.
Once Upon a Time: In the Season 1 finale, Emma and Regina briefly team up in order to save Henry's life.
Regina later teams up with Mr. Gold in Season 2, in order to stop Regina's mother, Cora, from getting into the real world.
Season 2 ends with a massive one between Regina, Emma, Snow, Charming, Gold, and Hook to save Henry (again) after he gets kidnapped to Neverland. The team-up has...varying levels of success.
Oz: Happens all the time in this prison drama as the various factions struggle for control of the drug trade, or seek to murder a rival.
Person of Interest: In her war against HR, Joss Carter first allies herself with crime boss Carl Elias and then has him form a temporary alliance with the rival Russian syndicate.
Power Rangers: Certain incarnations have done this, particularly Power Rangers Zeo. The Big Bad of the moment has brainwashed The Hero and the Sixth Ranger's attempt to save him has failed. It turns out that last year's villains have the technology to send the rest of the team over. They do, just to screw around with the new villains.
Likewise, a villain variant of this was completely subverted in Turbo: A Power Rangers Movie. Newly anointed Big Bad Divatox calls decayed villain Rita Repulsa for help, and gets laughed at. Rita's Captain Obvious response is that if she knew how to defeat the Rangers, she would have done it already.
Revolution: As of episode 14, the Resistance and the Georgia Federation have allied to open a two front war against Monroe.
In season 2, the heroes end up allying with pretty much all their surviving enemies since they need to top the Patriots before they take over most of the old United States and enact their genocidal policies.
Robin Hood: In the first season of the BBC's show Robin and the sheriff temporarily fight side-by-side in order to defeat a group of Saladin's assassins. In the third season Robin and Guy team up in order to save their half-brother Archer from execution.
Saturday Night Live: No matter how much Sean Connery would try to antagonize Alex Trebek during the Celebrity Jeopardy skits, the two of them would often commiserate over another contestant's idiocy—note the skit where they both snark on Anne Heche's nutty behavior.
Scrubs: Even features this trope when Dr. Cox and Dr. Kelso team up to break the spirit of an overly cheery coworker. However, she outsmarts them and they are back to mutual hate by the end of the episode.
Another episode featuring Dr. Kelso has him realizing one of the reasons the hospital keeps going is that everybody is united against him. In the future he'll purposefully invoke it to keep the staff going in moments of stress or instability.
There are also various times in season nine where the good guys have teamed up with TessMercer. Chloe in particular joined forces with Tess in episodes like "Upgrade" and "Sacrifice" so that they can both protect their secrets. (Tess's season ten Heel-Face Turn takes the 'enemy' out of the equation, so all post-S9 teamups aren't this trope.)
Stargate Atlantis: Sheppard and a wraith cooperated to escape custody of Kolya in the episode "Common Ground". This included the wraith feeding on Sheppard to have the strength to fight off their enemies, giving it the opportunity to double-cross our hero. However, he returned all the Life Energy he took (and possibly made up for a few months Sheppard spent in a time-dilation field) and Sheppard made good on his promise to let it go free. The wraith in question, later dubbed "Todd", would become a recurring character, and is notable for being unusually sociable for a Wraith, even joking with the heroes.
Taken Up to Eleven in the final battle against the Asurans, where the Earth, Traveller, and Wraith ships fight side by side against the Asuran warships in what is hands down the single most awesome space battle any of the three series has managed (Stargate Universe, being set on a Cool Starship, had a chance to top it before it was cancelled). This is even more impressive given the distinctly quarrelsome nature of the Wraith, thus the battle is a meld of nine factions (7 Hives, Atlantis and the Travellers) rather than 3 as some may think.
Stargate SG-1: Features this a great many times. It seems to be one of the favorite negotiating tactics of the Tau'ri in particular.
Ba'al has had to join forces with SG-1 to defeat his master Anubis and the greater threat of the Replicators during the "Reckoning" two-parter. This is not the last time they'd work with him. Initially subverted, as Ba'al asked SG-1 for an alliance and was flat-out rejected by Jack O'Neill.
O'Neill: I've got a better idea, instead of helping you, why don't we sit around and watch you get your ass kicked? That way you'll be dead, and we'll be glad.
Special mention just has to go to the two-parter "The Quest", where SG-1, Ba'al, andOri messiah Adria team up to solve Morgan le Fay's puzzles.
There is also an SG-1 episode entitled "Enemy Mine", though it is unrelated to this trope at first. The conclusion is somewhat an example of this trope, as the Colonel overseeing the mine and the Unas definitely considered each other enemies until the compromise where they agreed to work the mine themselves so long as it contributed to killing some Goa'uld. Plus they look a little Enemy Mine Lou Gossetty, what with the scaly skin and labored manner of speaking.
The original alliance (the one led by Ra) against Anubis, whose crimes were apparently considered unspeakable, even amongst the System Lords. Think about that.
Sokar was banished from the System Lords for much the same reason, and by much the same method.
According to Thor in "Fair Game", it is precisely because of the concept of "enemy of my enemy" that the Goa'uld System Lords banded together in the first place. Due to their Always Chaotic Evil nature, however, it takes a serious threat (like the Tau'ri) to convince them to work together for any extended length of time.
The "Giant Aliens" (later named Omeyocans by the novel City of the Gods) in the episode "Crystal Skull" quote the full line verbatim to SG-1. In Mayan, no less. And then they're never heard from again.
Then there's the various times the SGC temporarily allied with Lord Yu. To paraphrase Daniel Jackson, Yu is not to be liked or trusted, only trusted to make a practical decision unhampered by the usual Goa'uld mindset.
Star Trek: In general this franchise is all over this trope. The Klingons team up with the Enterprise crew in "Day of the Dove", the Klingons allying with the Romulans against the Federation and then later with the Federation against the Romulans, Voyager teaming with the Borg in "Scorpion", The Alliance of the Alpha Quadrant (and the poor, forgotten Beta Quadrant!) against the Dominion, etc., etc.
Star Trek: Deep Space Nine: Kira, Damar and Garak loathe each other. The fact that Damar killed Garak's Love Interest and Kira's surrogate daughter a few seasons back does not help. Eventually, the fate of Cardassia, and with it the entire Alpha Quadrant, rests on the three of them putting aside their differences and working together to create a rebellion to overthrow the Dominion control of Cardassia. It even leads to the beginning of Fire-Forged Friends.
The Andorians and Vulcans learning to work together have some shades of this trope (though the fact that one of the enemies faced together is extremist elements in the Vulcan governments complicates matters), especially during the last season (the Romulans' meddling intended to break the Coalition ends up strengthening it by giving them a common foe: the Romulans. Oops).
Rather famously, the Tamarian for this trope is "Darmok and Jalad at Tanagra."
TNG also did it in "The Enemy", where Geordi and a Romulan had to work together.
Star Trek: Voyager: This is the plot, although by the third season the rival crew factions have been forgotten.
In a later season of Voyager, in the episode where the Delta Flyer is introduced, B'Elanna Torres learns that the Maquis lost back home. She turns depressed and does dangerous things in the Holodeck with the safety off, and because most of the ship has all but forgotten their initial division between Starfleet and Maquis, they don't know what's wrong with her.
When they first re-establish contact with Starfleet, Janeway mentions to Chakotay that she actually had forgotten the implications of the mixed crew after they had been working together for so long. She becomes concerned for what happens when they got home, since as far as Starfleet are concerned, the former Maquis crew are still wanted terrorists?!
Janeway's alliance with the Borg in Delta Quadrant against Species 8472 (where the crew picks up 7 of 9).
Supernatural: In season 5, Sam, Dean, and the others join forces with the demon Crowley in an attempt to defeat Lucifer.
An odd example when Gabriel joins forces with the Winchesters and goes up against Lucifer, resulting in his death, since he spent most of the time he knew them tormenting them. Although it's implied that he knew that they'd eventually do, which is why he gave them such a hard time.
And later join forces with Meg to defeat Crowley.
Which is an interesting use of this trope, seeing as Meg was a staunch Lucifer loyalist whom the boys had fought against in the same episode they first allied with Crowley.
In season 7, the Winchesters are aided by several old enemies (Meg, Crowley, and the Alpha vampire) at different points and for various reasons in order to defeat the Leviathans. Of the three, Crowley is the one who double-crosses them when things are over and done with.
When Dean was trapped in Purgatory for a year between seasons 7 and 8, he teamed up with a vampire named Benny in order to escape.
Teen Wolf: Scott, Allison, Chris, and Kate versus Alpha Peter Hale in the season one finale.
And then not-so-Alpha Peter with Derek versus Gerard and Kanima Jackson in season two.
Terra Nova: The episode "Now You See Me". Taylor and Mira's "Your place or mine" hostage struggle is interrupted by a pair of young and territorial Slashers. Leading to Taylor to hand a knife to Mira and say “We can fight each other, or we can fight them.”
Time Gentleman Please: Played for Laughs. The Pub Landlord loathes the French, due to his wife running away with a Frenchman and taking his beloved son away from him. In one episode, the Frenchman walks into his pub, causing him to immediately begin a tirade, before the Frenchman cuts him off and reveals that she's left him... for a German.
Pub Landlord: *Shakes hand* The mutual enemy, all hostilities are now ceased!
The Vampire Diaries: Damon will take a break from harassing Stefan if there's a bigger threat, or if it's in his interest.
If the promo for "Before Sunset" is any indication the brothers will work with Klaus to stop Alaric.
In the episode A Necessary Evil of Xena: Warrior Princess, Xena enlists the aid of her enemy Callisto to fight Velasca, an Amazon who acquired the powers of a goddess. At that point, Callisto had recently become immortal and was the only person available to go up against her, despite Gabrielle's protestations.
The X-Files: The episode "En Ami". And "Tunguska"/"Terma" as well, although that turned out to be a set-up.