In William King's novel Space Wolf, the Marines chose Ragnar and Strybjorn for Marines when they were fighting each other to the death, and both were mortally wounded. Ragnar's desire for Revenge is kept at bay by the knowledge that the Marines will not let him. Finally, when they are fighting Chaos Space Marines, Strybjorn saves Ragnar's life, and shortly thereafter goes down. Ragnar realizes that he neither should nor does want Strybjorn to die; he sends the others on and stays to treat and bring Strybjorn with them.
The first Ciaphas Cain novel, For the Emperor, forces the Imperial Guard into an uneasy truce with a Tau diplomatic security contingent because neither side considers the crappy backwater planet Gravalax worth getting into an all-out war over. It turns into Enemy Mine after the two sides discover there's a genestealer cult trying to provoke that war, and the Tau aid the Guard in restoring order. The suicide squad Cain puts together from condemned Guardsmen joins up with a Tau pathfinder unit down below, while on the surface, a Tau Hammerhead hover-tank helps the 597th break through a traitor PDF position.
History Repeats in the ninth novel, The Greater Good, where the Tau and Guard start out fighting, then are forced to join forces when their war is rudely interrupted by a tyranid hive fleet.
And in the Warchild Series, Captain Azarcon, a Space Marine, and Niko, human sympathizer of the alien resistance work together to rescue hostages and capture gunrunners. This collaboration leads to the end of the war... for a time, anyway.
In E. E. “Doc” Smith's The Skylark of Space, the villain DuQuesne agrees to act as one of the party until they return safely to Earth, even though he wants the hero Richard Seaton dead. Ultimately Seaton makes his best friend hand BOTH his guns over to DuQuesne because DuQuesne is the better shot, and then Seaton and DuQuesne stand side by side and mow down their common enemies until all four guns are empty. In Skylark DuQuesne, DuQuesne enlists Seaton's help in fighting an otherwise unstoppable alien menace and ends up winning the war and saving Seaton's life in the process, though by this time his reasons for wanting Seaton dead no longer apply. The fact that each man at least respects the other's abilities helps.
The Truce at Bakura is this trope personified, with the Imperials forced to work with the Rebels to defeat the evil Ssi-Ruuk. Once it becomes clear that the aliens are in retreat, the Empire reverts back to their evil selves and re-declares war on the Alliance.
A couple of times in the New Jedi Order. In Conquest, Anakin Solo teams up with Yuuzhan Vong warrior Vua Rapuung to rescue his friend Tahiri from a Mad Scientist who is also Rapuung's enemy (and ex-lover). In the last book, The Unifying Force, Han Solo and Boba Fett find themselves briefly fighting side-by-side against Vong warriors. Finally, at the very end of the series, a subversion comes into play- Nom Anor, Recurring Boss for most of the series, allies with the heroes only out of a selfish sense of self-preservation, and immediately tries to flush them out an airlock when he feels they've outlived their usefulness.
In Honored Enemy, a band of Kingdom raiders allies with a Tsurani patrol in order to survive pursuit from a Moredhel company. The story plays during the war between the Kingdom and the Tsurani and revolves around the tension this causes.
In Betrayal at Krondor, the moredhel chieftain Gorath seeks out Prince Arutha to curb another upcoming invasion that he feels would be too costly for his people.
The Animorphs only teamed up with their main enemy, Visser Three, twice: to defeat a race of annoying, psycho, tiny-tiny-tiny aliens with a shrink ray and a mass Napoleon Complex, and to escape from a bunch of mutated blue fish-people that want to kill and stuff them for their Derelict Graveyard. On the other hand, Visser One freed them from Visser Three's prison in her very first appearance. Since the Animorphs are guerrilla fighters and Visser One is the main advocate for a stealth invasion (and her host is Marco's mom), they're not unwilling to accommodate her if it hurts Visser Three's credibility — but they're not unwilling to use it as an excuse to double-cross her, either...
In Elfangor's Secret, the Ellimist and Crayak both agree that the Time Matrix should not be in the hands of a mere mortal and help the Animorphs stop Visser Four.
In the last few books, they team up with Tom and his followers in order to hijack the Pool Ship. Both sides then double-cross each other, but the Animorphs end up winning in the end.
In The Other Wind, the last (so far) in Ursula K. Le Guin's Earthsea series, representatives of four cultures normally at loggerheads - if not outright enmity - have to pool their respective mythological knowledge in order to figure out the truth about an ancient evil.
In the Crown of Slaves sub-series of the Honorverse, Victor Cachat and Anton Zilwicki are two intelligence operatives from the warring Star Empire of Manticore and the Republic of Haven (Formerly People's Republic of Haven). They team up to investigate Mesan intrigue and how it impacts the war. It's implied this sub series may lead to a Grand Alliance...
Really, by now it's evident that The Climactic Conflict will be between the Andermani/Havenites/Manticore/Maya/Beowulf/Torch/others versus the frikkin' huge Solarian League (minus bits like Maya)/Mesa/whatever else we haven't seen yet. It promises to be awesome.note Though in context, Manticore and (post-Theisman Coup) Haven are natural allies, particularly considering how vehemently both of them enforce the Cherwell Convention. Now that the reason for the war — the PRH's expansionist policies — is gone, the true Republic has been restored, and all the diplomatic snafus are cleared away, it would have been more surprising if they hadn't allied together.
As of Mission Of Honor, Manticore and Haven have signed both a peace treaty and a military alliance.
In the The Eternal Champion story by Michael Moorcock, humanity has unified solely because of the presence of the alien Eldren. Ekrose, the protagonist states that, absent the Eldren presence, humanity would be at war with itself. This is a key reason for his decision to kill the entire human race
This is a major part of the plot of all 3 novels in CS Friedman's Coldfire trilogy: an immortal vampire and a priest team up to fight mutual enemies. By the end of the novels, the priest has been thrown out of his church and the vampire's patron Dark God has rescinded his immortality and cast him into Hell for being insufficiently evil. Turns out saving the world isn't compatible with maintaining that black-as-a-moonless-night karma, who knew?
The Hobbit. The dwarves are about to fight a battle with the Lake-men and Wood-elves to determine who will gain Smaug's treasure. Gandalf appears and warns them that an army of goblins and wargs is approaching, and they must join together to fight the evil attackers.
In Dragonlance, black robed mages ally themselves with the good guys every now and then, for example to drive off the Dark Queen in Legend of Huma and during the War of the Lance. Dragons of Summer Flame was based around this trope. Also Fistandantilus and the Kingpriest used each other for their own goals.
In The Legend of Drizzt Drizzt Do'Urden and Artemis Entreri must team up and fight back to back in an effort to get out of the Underdark at one point.
It is briefly mentioned in the Warhammer 40,000 novel Grey Knights that the underhive gangs of Volcanis Ultor "buried their enmities for one long night" to do battle with a powerful gang of Chaos followers.
Star Wars: While most of the clone troopers went on to serve the empire, the True Mandalorians (a.k.a. the group that nearly destroyed the Galactic Republic 4,000 years ago) fought alongside the rebels to retain their heritage as well as kill those who had betrayed their own kin.
Speaking of Fate of the Jedi, Apocalypse reveals that the Father, the Son, and the Daughter had fought against Abeloth multiple times after she got corrupted. The mere fact that the Son, who is the embodiment of the Dark Side, would ally himself with the Daughter, who is the embodiment of the Light Side, even when they would more often than not fight each other to the death had it not been for the Father's influence would imply that this trope came into play.
A Song of Ice and Fire has some interesting ones. Jaime Lannister and Brienne of Tarth are forced to coexist when Catelyn Stark sends Brienne to trade Jaime for Sansa, but though they start out quite hostile, they've reached a point of sort-of friendship and mutual respect (and maybe more). A more hostile camaraderie briefly exists between Sandor Clegane and Arya Stark; she still hates him, sure, but when it comes down to it they work well together, and she's probably more like him than she'd like to acknowledge. On a larger scale in A Dance with Dragons the wildlings and the Night's Watch agree to work together against the Others. Many of them aren't happy about this, rendering the alliance extremely tenuous.
While they never actually get round to fighting, Stannis Baratheon makes it clear he views Robb Stark as just as much of an enemy as Big Bad Joffrey Baratheon. By Book 5, Robb has been betrayed and killed by some of his own soldiers, while Stannis' forces have been decimated. Subsequently, the Northern soldiers who remain loyal to the Starks join up with Stannis.
Reversed in the Star Trek Expanded Universe. In the wake of the Borg invasion, several previously non-aligned minor enemies such as the Tholians join the Typhon Pact in order to leave the Federation and Klingon Empire surrounded by a hostile power. The Tholians, well-known for xenophobia, join for this reason alone.
The Dale Brown novel Air Battle Force culminates in the Taliban detachment that served as primary enemy of that book working with Turkmen and American forces against the Russians, which continues into Plan of Attack.
Edge of Battle has Zakharov and Task Force TALON reluctantly cooperating after Comandante Veracruz's double-cross, though it doesn't last.
Strike Force is centred on an Iranian coup leader and former enemy of Dreamland who now needs their help. The blurb tells you as much!
A Pict Song by Rudyard Kipling. "No indeed! We are not strong, But we know Peoples that are..."
The White Rose by Glen Cook. In the final battle the Lady — sorceress leader of the northern empire — needs the help of the white rose to take down the dominator, her husband and a much better sorcerer. The white rose creates a area where magic cannot be used and therefore is vital to taking down the greatest sorcerer in known history.
In Streams of Silver, Drizzt Do'Urden and Artemis Entreri declared a temporary truce in order to join forces against a common enemy (the gray dwarves inhabiting Mithral Hall). Some time later, in Starless Night, Catti-Brie and Entreri teamed up to rescue Drizzt from the drow, who were holding all three of them captive and who would have eventually executed both Drizzt and Entreri. (Or condemned them to a Fate Worse than Death.)
Artemis Fowl and Holly do this in The Arctic Incident and The Eternity Code — they are opponents, or at the very least rivals with a sore history, even though they have both saved each others' lives. In The Arctic Incident, they cooperate as part of a deal: Artemis uses his above-world influence to investigate a smuggler, while the LEP use their advanced technology to help rescue Fowl Senior. In The Eternity Code, their relationship is more tense as they cooperate to resolve a situation Artemis is partly to blame for. By The Opal Deception, they are friends, and later possibly more than that, though that does not go anywhere.
A complicated example occurs in the "Richard Bachman" (actually Stephen King) novel The Regulators. The demon Tak is possessing a young autistic boy, and is somehow using the boy's unique mind to augment and give shape to its supernatural power. Both the boy and the demon are fans of cheap westerns and a Power-Rangers style TV show, both of which the demon uses as inspiration for his means of destroying the town. In the show-within-a-show, the heroes team up with their enemy to stop a something from destroying Earth. Tak channels this as the final assault on the protagonists.
Sam and Caine of the Gone series (who are ironically brothers) have teamed up twice during intervals of trying to kill each other;
They teamed up in Hunger, against Drake Merwin. Sam wanted him dead because he tortured him senselessly and this was enough to piss even him off, and Caine's motive was spontaneous rage for him trying to his girlfriendDiana.
In Lies they have reluctantly paired up again to murder Caine's daughter.. They fail miserably, but it's a awesome fight scene.
In Shattered Sky, the third book in the Star Shards Chronicles trilogy, the good guys team up with Okoya, the villain of the second book to defeat a greater enemy that threatens to destroy the universe.
In The Trail of Cthulhu, it's revealed that Professor Shrewsbury and Hastur (presented here as Cthulhu's rival brother) have struck an alliance to keep Cthulhu from waking up.
In The Dresden Files series, Harry teams up with Lara Raith multiple times over the course of the series to help them reach mutual goals.
They do this quite often in fact, to the point at one instance Lara indicates quite clearly she would rather rule with Dresden together than for them to keep fighting each other.
He does this even more with crime lord John Marcone; it eventually gets to the point where they've had common goals so often, they're more enemies in principle than practice.
The novel Turn Coat is one long, extended Enemy Mine sequence between Harry and his former nemesis Donald Morgan, who finds himself needing Harry's help to survive.
In the Codex Alera series, the Canim have Gadara, meaning "trusted enemy". Gadara can often work together, as Tavi and Varg eventually do.
The trope is carried much further with the appearance of the Vord, which allows the First Lord to forge tentative alliances with all of Alera's long-standing enemies to fight together against the new opponent. In fact, the First Lord ends up saying the Vord was the best thing to happen to Alera.
In The Man from U.N.C.L.E. novel The Dagger Affair by David McDaniel, UNCLE and THRUSH operatives work together to stop DAGGER, a new organization armed with advanced science. In the end a THRUSH-controlled fighter jet kamikazes the DAGGER base, using sheer momentum to overwhelm its force field. There's a poignant moment where the leader of THRUSH reminds the leader of UNCLE of their former friendship and gives him a copy of 1984. Then he ends the truce ahead of the agreed time, not that anyone expected anything else. We also discover that the full name of THRUSH is the somewhat unwieldy "Technological Hierarchy for the Removal of Undesirables and the Subjugation of Humanity".
In the second book of the Mistborn trilogy, Vin finds herself working with an enemy - Ten-Soon, who had assumed the identity of Ore-Seur, and had been working on behalf of Straff Venture.
This happens in The Path to War where Tahniya is soul bound to Zan as punishment; they can't stand each other.
Bertie Wooster and Sir Roderick Glossop team up in Thank You, Jeeves and end up getting along very well, even exchanging invitations to lunch. Bertie notes that he can't be all bad, since he beat up Chuffy's Bratty Half-Pint cousin Seabury.
This is the plot of Harry Harrison's Stars and StripesAlterhate History trilogy. After the British declare war on the Union, they accidentally sack a Confederate town instead of a Union fort (the stars-and-bars flag confuses them). In response, the Union and the Confederacy agree to a cease-fire and, eventually, the Confederacy re-integrates into the USA and abolishes slavery in the face of the British Empire. One of the main criticisms of the trilogy is how easily this happens without too many problems.
The alliance of the outlawed Malazan commander Dujek Onearm with his enemy Caladan Brood against the omnicidal Pannion Seer in the third volume of The Malazan Book of the Fallen. It later turns out that Dujek's outlawry was a Xanatos Gambit by Malazan Empress Laseen to win Caladan's support for the war.
In Tom Kratman's Caliphate, in spite of a continuing state of low-level conflict between them, the Imperial States of America and the Celestial Kingdom of the Han (China) work together to eliminate a significant bioweapon threat posed by the eponymous Caliphate.
The premise is Baalaria and Drewghaven teaming up to quell raiders produced by civil unrest.
Zarracka and Mordak team up because they both hate Daniar.
Everyone still alive joins forces against Kthonia.
In Andre Norton's Catseye, faced with Troy's suspicion, Rerne proposes that they join forces against a common foe.
A typical strategy in The Hunger Games, especially used by the Careers. Involves forming alliances with one or more other tributes to help each other, stay alive longer, and maybe take out other tributes. But of course, these can only be temporary, since the pool of remaining tributes gets smaller and smaller... There's only one victor, after all.
In A Passage to India, which is set in the British Raj, the religious divisions among native Indians - particularly those between Hindus and Muslims - are only set aside when they find themselves both in conflict with the ruling British authorities. As Dr Aziz says to Cyril Fielding, "We may hate each other, but we hate you more."