Overlaying low-power, low-cost, femtocells, over existing wireless networks has recently emerged as a means to significantly improve the coverage and performance of next-generation wireless networks. While most existing literature focuses on spectrum sharing and interference management among non-cooperative femtocells, in this paper, we propose a novel cooperative model that enables the femtocells to improve their performance by sharing spectral resources, minimizing the number of collisions, and maximizing the spatial reuse. We model the femtocell spectrum sharing problem as a coalitional game in partition form and we propose a distributed algorithm for coalition formation. Using the proposed algorithm, the femtocells can take autonomous decisions to cooperate and self-organize into a network partition composed of disjoint femtocell coalitions and that constitutes a stable partition which lies in the recursive core of the considered game. Whenever a coalition forms, the femtocells inside this coalition can cooperatively pool the occupied spectral resources. Additionally, the members of any given coalition jointly schedule their transmissions in order to avoid collisions, in a distributed way. Simulation results show that the proposed coalition formation algorithm yields a performance advantage, in terms of the average payoff (rate) per femtocell reaching up to 380% relative to the non-cooperative case.