England and Japan form an alliance at one point in Axis Powers Hetalia because of this. The strip featuring this event is even titled "The Anglo-Japanese Alliance Between Two Lonely People."
Due to their histories of being isolationist, some fans have started to group America, England and Japan together as the "Lonely Trio".
In fandom, the Russia/China pairing gets this, as the two are, in canon, the more outcast of the Allied Forces. It also helps that they were about the only major Communist forces during the Cold War and pretty much banded together against the rest of the world (for some time, at least).
Prussia/Canada also gets this, as many fans like the idea of the lonely ex-nation finding a sympathetic ear in the forgotten nation and vice versa.
This trope comes into play during tender scenes of Neon Genesis Evangelion in which the protagonists show a kindred spirit toward each other (although this rarely lasts). Usually comes into play between Shinji and one of the female protagonists (especially Rei).
Also subverted. There's a symbolic (?) scene where Asuka rejects Shinji and bitterly accuses him of only approaching her to stave off his own loneliness, saying anyone would do in her stead.
Played straight in volume six of Angelic Days where Rei and Ritsuko lament on that they both fell into the same situation: loving an Ikari who doesn't return their feelings but instead loves someone else. Ritsuko is highly jealous of Yui and Rei is worried that her synch ratio is dropping because she still loves Shinji but he's with Asuka.
In Bleach, despite their contrasting personalities, Starrk and Lilynette — two Arrancars that had been split from the same Hollow — have stayed with each other ever since out of their loneliness and desire for friendship. They even (possibly) died together while a flashback of when they met for the first time is shown
Turns out this is how Gin and Matsumoto met and became friends, too.
Cowboy Bebop: None of them will ever admit it, but this is one of the biggest reasons the crew of the Bebop stay together.
Kikyou and Inuyasha got together like this in the past. Kikyou was a very respected Teen GeniusMiko, but people tended to not see beyond this facade and thus, save for her little sister Kaede, she was very lonely. On the other hand, Inuyasha was a half-Youkai and thus was ostracized ever since childhood by both humans and youkais. Kikyou treated Inuyasha with kindness, Inuyasha treated Kikyou without making distinctions... therefore, they started to fall in love and decided to wish on the Shikon no Tama so he would become a human, which would allow them to stay together. Then, Naraku happened.
In the manga version of Chrono Crusade, Viede guesses that Fiore and Joshua might care for each other so much because they're both "missing something" — that is, they've both been separated from a beloved sibling ( Satella, for the first, Rosette for the latter).
In Power Pack, when their mother was in the hospital, Katie invited several characters they had met to have Thanksgiving with them. This infuriated her brothers and sister, and at the climax she explained that when they met the Morlocks, her sister had told her how she had realized it was better to be alone and miserable together, and so she had invited everyone else who had no one else to celebrate Thanksgiving with. Her older brother declares that they can have a party, if they're going to be miserable at it.
In a recent issue of Wonder Woman, Diana and her frequent opponent, Giganta, take a brief time out in fighting to discuss their respective man troubles. As much as Giganta hates Diana, she does offer advice all the same.
The theme of Mozart And The Whale .
Lost in Translation. Bob, the over-the-hill movie star, and Charlotte, the tag-along wife of a busy photographer, have nothing in common except insomnia and loneliness. If they didn't happen to be staying at the same hotel, they'd never have met.
Poul Anderson's "Losers' Night": The Old Phoenix, the Inn Between the Worlds, has a night where all the guests are failures. Unusually for the inn, this night allows people to magically understand each other — so they can commiserate.
In an Outlander novel, Claire and Lord John got married and slept together because they both thought Jamie was dead.
"You are a barbarian, and I am an outcast, denied by my people. We are both pariahs, wanderers of earth. Oh, take me with you!"
This is how P. G. Wodehouse's Psmith got his start as a character; he and pre-existing character Mike Jackson were pulled out of their respective schools and exiled to an obscure school called Sedleigh. Wodehouse also used this trope in his romantic fiction to set up young couples; Something Fresh is a good example.
In The Hunger Games, Katniss and Madge (the mayor's daughter) are loners at school and so end up partnered together for school events and projects by default.
Initially when Semi and Miranda become close in Dr Franklins Island it's partly this. They were friendly before, and Semi needed Miranda, but it's when the third member of their party vanishes and they are otherwise completely alone that they really end up close, and finding that there are similarities after all.
From Scrubs, after J.D. and his girlfriend realise their incompatibility;
J.D.: So I guess...this is over. Danni: Why? J.D.: So, you'd rather hang out with someone you don't even like than be alone? Danni: Yeah, pretty much. J.D.: Yeah, me too. I mean, come on, how many couples out there actually have fun together?
Heroes: Sylar and Peter as of Season 4 episode 18 (or around there), The Wall. Rather forced on them since spending five years with only each other as company would suck pretty badly, especially if it's with the guy who killed your brother. It appears that their reluctant alliance will last into the real world.
On NCIS, after a story arc where they both gain significant others, Tony and Ziva note that no matter what happens, at the end of the day, they're always the ones sharing drinks alone in a bar together.
Happened once in That '70s Show, when Jackie was lonely, Hyde suggests that she find someone to spend time with (specifically, Donna, or someone that's not him). However, Jackie mentions that he's alone a lot too, before stating:
Jackie: You're alone. I'm alone. We could be alone together!
Friends: Chandler and Monica have a moment in Season 4. Chandler is in love with Joey's girlfriend, and Monica is boyfriendless and ill. On finding each other wearing pj's and wrapped in blankets, they curl up miserably together.
On Babylon 5, Lennier and Vir are shown sitting at a bar commiserating on a number of occasions, having similar concerns about their jobs and various ongoing situations. It is implied that this is something they actually do on a regular basis, despite their bosses spending a significant portion of the show on opposite sides of the larger conflict.
Comes up a few times in Cheers. In particular the episode Thanksgiving Orphans, where the gang can't be with their loved ones on Thanksgiving and instead eat dinner at Carla's. In the end, they declare they're thankful for all the people they miss, (Norm's wife, Cliff's mother, the recently-deceased Coach) since it does mean they have people they care about.
In the musical Promises Promises, Chuck and Marge, acquaintances from work, sing "A Fact Can be a Beautiful Thing" while hanging out in a bar on Christmas. (I'll add more info after I get the libretto out again. It's been a while.)
A song in Spamalot titled "I'm All Alone" starts with King Arthur singing about how alone he is, and Patsy reminding him that he's right there, while the king is singing the song. Then the chorus comes in and sings "We're all alone," leading to:
King Arthur: We must be lonely side-by-side. It's a perfect way to hide.
Leela: You didn't need to buy me a present, Fry. Fry: I just wanted to do something to make you happy. I mean, I miss my family but you never even had a family. Leela: It's OK. You're lonely and I'm lonely. But, together, we're lonely together. [They hold hands] Fry: Merry Xmas, Leela. Leela: Merry Xmas.
In the Justice League episode "Hereafter", Vandal Savage and a time-displaced-and-depowered Superman are stuck on a barren future Earth devoid of all other human life. The driven-to-sanity Vandal Savage is overjoyed to meet a fellow person, even if he is an old enemy, and invites him to his house for lunch. And to show him all the self-help books he's read over the millennium to cure his megalomania.
The Thanksgiving episode of Hey Arnold! does this to Helga and Arnold, even though they have families, they feel alone like they've never truly celebrated Thanksgiving before, so they bond with each other as they try to find the perfect Thanksgiving.