Numerical models indicate that collective animal behaviour may emerge from simple local rules of interaction among the individuals. However, very little is known about the nature of such interaction, so that models and theories mostly rely on aprioristic assumptions. By reconstructing the three-dimensional position of individual birds in airborne flocks of few thousands members, we prove that the interaction does not depend on the metric distance, as most current models and theories assume, but rather on the topological distance. In fact, we discover that each bird interacts on average with a fixed number of neighbours (six-seven), rather than with all neighbours within a fixed metric distance. We argue that a topological interaction is indispensable to maintain flocks cohesion against the large density changes caused by external perturbations, typically predation. We support this hypothesis by numerical simulations, showing that a topological interaction grants significantly higher cohesion of the aggregation compared to a standard metric one.