According to the social brain hypothesis, group-living primates tend to be more intelligent and have bigger brains than their less social cousins. The idea is that competing and cooperating with one's fellows takes smarts. Individual animals who are better at these social interactions are more likely to transmit their genes to future generations. Over evolutionary time, you get a smarter species.
Social complexity seems to matter more than simply hanging out and interacting with one's conspecifics. Having to negotiate social hierarchies, build alliances, and repair strained relationships requires considerable brain power. Hence, chimps are smarter than gorillas.
But wait! Who is the smartest ape of them all? Not counting humans, of course. That's right - the relatively solitary orangutan.
Ok, intelligence isn't exactly a tightly measurable concept. And inquiring minds may disagree. Still, according to one influential ranking, orangutans win the prize.
References:
Barrett,L. and Henzi, P. (2005) The social nature of primate cognition. Proceeding of the Royal Society B 272 1865-1875; DOI: 10.1098/rspb.2005.3200.
Byrne, RW (1997) The technical intelligence hypothesis: an additional evolutionary stimulus to intelligence; in Machiavellian Intelligence II: Extensions and Evaluations. eds. A Whiten and RW Byrne. Cambridge University Press, p. 289-311.
Deaner RO, van Schaik CP, Johnson VE (2006) Do some taxa have better domain-general cognition than others? A meta-analysis of nonhuman primate studies. Evolutionary Psychology 4:149–196.