It has commonly been thought that snakes underwent progressive loss of their limbs by gradual diminution of their use1. However, recent developmental and palaeontological discoveries suggest a more complex scenario of limb reduction, still poorly documented in the fossil record2,3,4,5. Here we report a fossil snake with a sacrum supporting a pelvic girdle and robust, functional legs outside the ribcage. The new fossil, from the Upper Cretaceous period of Patagonia, fills an important gap in the evolutionary progression towards limblessness because other known fossil snakes with developed hindlimbs, the marine Haasiophis, Pachyrhachis and Eupodophis, lack a sacral region. Phylogenetic analysis shows that the new fossil is the most primitive (basal) snake known and that all other limbed fossil snakes are closer to the more advanced macrostomatan snakes, a group including boas, pythons and colubroids. The new fossil retains several features associated with a subterranean or surface dwelling life that are also present in primitive extant snake lineages, supporting the hypothesis of a terrestrial rather than marine origin of snakes.