There are plenty of prime examples of greedy humans cooperating. Corruption, cartels, price fixing, collusion in general, ...
More seriously: one of the major struggles of society is setting up incentive structures that align the interests of the individual with that of the group, so even people acting in their own self interest still contribute to the greater whole. We only managed to go to the moon because we managed to turn an utterly selfish ideological struggle into a space race.