Dynamics of populations on the verge of extinction