Flapping wings produce lift and thrust in bio-inspired aerial robots, leading to quiet, safe and efficient flight. However, to extend their application scope, these robots must perch and land, a feat widely demonstrated by birds. Despite recent progress, flapping-wing vehicles, or ornithopters, are to this day unable to stop their flight. In this paper, we present a process to autonomously land an ornithopter on a branch. This method describes the joint operation of a pitch-yaw-altitude flapping flight controller, an optical close-range correction system and a bistable claw appendage design that can grasp a branch within 25 milliseconds and re-open. We validate this method with a 700 g robot and demonstrate the first autonomous perching flight of a flapping-wing robot on a branch, a result replicated with a second robot. This work paves the way towards the application of flapping-wing robots for long-range missions, bird observation, manipulation, and outdoor flight.