We present an autonomous visual landmark recognition and pose estimation algorithm designed for use in navigation of spacecraft around small asteroids. Landmarks are selected as generic points on the asteroid surface that produce strong Harris corners in an image under a wide range in viewing and illumination conditions; no particular type of morphological feature is required. The set of landmarks is triangulated to obtain a tightly fitting mesh representing an optimal low resolution model of the natural asteroid shape, which is used onboard to determine the visibility of each landmark and enables the algorithm to work with highly concave bodies. The shape model is also used to estimate the centre of brightness of the asteroid and eliminate large translation errors prior to the main landmark recognition stage. The algorithm works by refining an initial estimate of the spacecraft position and orientation. Tests with real and synthetic images show good performance under realistic noise conditions. Using simulated images, the median landmark recognition error is 2m, and the error on the spacecraft position in the asteroid body frame is reduced from 45m to 21m at a range of 2km from the surface. With real images the translation error at 8km to the surface increases from 107m to 119m, due mainly to the larger range and lack of sensitivity to translations along the camera boresight. The median number of landmarks detected in the simulated and real images is 59 and 44 respectively. This algorithm was partly developed and tested during industrial studies for the European Space Agency's Marco Polo-R asteroid sample return mission.