It depends on what we mean by "greatest" foe.
By most standards, the Joker is considered Batman's greatest foe, because he's definitely Batman's arch nemesis and the villain who returns most often to cause Batman the greatest overall amount of trouble. He also has caused a body count into the thousands, which Batman blames himself for (because he won't kill the Joker), and among those he's harmed are people very close to Batman (he tortured Commissioner Jim Gordon, he shot and crippled Gordon's daughter, Barbara "Batgirl" Gordon, and he murdered Jason "Robin" Todd by beating him with a crowbar and blowing him up).
By being so unpredictable and having a personality that changes constantly (sometimes methodical in his plans, sometimes chaotic and random, other times playful and not homicidal, etc), he is one of the hardest foes for Batman to stop, too. And he is the villain who has the strongest personal connection to Batman in an emotional way, considering himself Batman's greatest foe and their conflict to be the defining one of Batman's mission.
However, there are other ways to consider "greatest," and as the question notes, Ra's al Ghul is one of the greatest Batman villains and perhaps the one whose plots are the most difficult for Batman to stop. Ra's is also one of the few villains who is nearly equal to Batman physically and mentally, and might be the villain for whom Batman has the closest thing to "respect." Ra's is, in some ways, like a dark mirror image of Batman.
Batman also has a very special connection to Ra's, because he once loved and married Talia al Ghul, the daughter of Ra's, and Batman is the father of Talia's son Damian. So Ra's, then, could make a case that he trumps the Joker as the largest scale threat who consistently presents the biggest challenge to Batman on the most levels.
I'm personally a big fan of Doctor Hugo Strange, who was introduced in Batman's tenth appearance. Strange appeared before almost all other of Batman's recurring villains -- only Doctor Death appeared earlier as a villain who would show up in future stories. Over the decades, Strange developed into one of Batman's most powerful enemies, deducing Batman's identity and essentially destroying Batman's personal life as Bruce Wayne before defeating Batman and taking Batman's place.
Batman himself considers Hugo Strange to be "the most dangerous man in the world," and Strange has certainly shown himself to be perhaps Batman's most consistently dangerous foe for Batman personally. It's possible that no other foe has bested Batman more often than Strange. I also doubt any other villain has infiltrated, manipulated, and ruined Bruce's personal life more thoroughly and consistently than Strange, either (although some have come close, and there's an argument that Dr. Simon Hurt came close to besting Strange's efforts in this regard). So in terms of success as a villain posing the greatest threat to Batman and Gotham City, Strange has a very strong record on which to make a case rivaling Ra's al Ghul in those regards.
Finally, there's a good argument to be made for Two-Face, if we think of "greatest" to mean the really best villain ever invented for Batman. Two-Face began as an ally for Batman, fighting on the side of law and order as District Attorney Harvey Dent. But in the aftermath of his severe injuries, then the evil in Gotham city fed and distorted some darkness within Dent. He came to reflect something about Batman and Gotham City, the narrative about duality and the conflict between good and evil with the humanity, and raised questions about our true nature (are we good people who sometimes give in to bad, or are we bad people who sometimes manage to resist our own nature and do good?).
Two-Face is probably the single best distillation of those elements and themes in the Batman mythos, and he best summarizes the broad concept about dual nature in Batman and Gotham and humanity, making him arguably the best villain representing what Batman and Gotham are all about, in terms of story and arc and redemption. Dent is beyond redemption, but Batman refuses to accept that anyone is beyond redemption and thus forever struggles to help Dent overcome his demons. So, that struggle and relationship may in fact be far deeper, more meaningful, more representative, and more fundamentally about the most important themes in Batman, than any other villain, and could be Two-Face's claim to the title of greatest foe.
I would say that depending on which angle you approach the notion of "greatest foe," there are these top four possible answers. My guess is that if you polled most readers, most Batman writers, and the general public, then the Joker would surely win by a pretty wide margin. But if anyone could challenge the Joker for the title, it would be one of these other foes listed here, and I think they have some very strong cases to make.
By Kavinay Kishor, Batman Geek
The Joker and Ra's al Ghul are the strongest villainous candidates.
On a different tack though, I'd suggest that Batman's greatest adversary is actually this guy:
That's right: Superman. This was overtly pointed out to us in The Dark Knight Returns, but the tension between Clark and Bruce has always been present whenever they're paired up.
It makes sense if you're familiar with how fundamentally different both heroes are. Their absolute moral imperative is the same, "do not kill," but most of their methods and points of view of are polar opposites. Frank Miller pointed out how Superman, as a stooge for the US government, and Batman, as a law unto himself, are destined for a climactic showdown at some point:
Even if you don't agree with Miller's line (Superman has since disconnected himself from representing purely US interests), Batman and Superman are always keeping tabs on one another. In fact, it's the premise behind most plots in the Superman/Batman books. And for good reason too, as the results would be catastrophic if either hero was left to run amok due to manipulation (i.e. mind control via Maxwell Lord).
Who did Clark entrust with kryptonite to stop him if magic or insanity ever make Superman lose control of his awesome powers? Yup, it's The Batman:
Whether he wants to or not, The Batman has the burden of being the only one empowered with the knowledge and tools to stop Superman. Bruce Wayne and Clark Kent are close friends, but they are only ever one abnormality away from being each other's most formidable adversary.
More questions on Batman:
- How might the next Batman movie franchise try to set itself apart from previous incarnations?
- I want to start reading Batman comic books, where should I start?
- How old are Batman, Spiderman, and James Bond?