Understanding animal episodic-like memory is important for tracing the evolution of the human mind. However, our knowledge about the existence and nature of episodic-like memory in nonhuman primates is minimal. We observed the behaviour of a wild male chacma baboon faced with a trade-off between protecting his stationary group from aggressive extra-group males and foraging among five out-of-sight platforms. These contained high-priority food at a time of natural food shortage. In 10 morning and 8 evening trials, the male spontaneously visited the platforms in 5 and 4 different sequences, respectively. In addition, he interrupted foraging sequences at virtually any point on eight occasions, returning to the group for up to 2 hours. He then visited some or all of the remaining platforms and prevented re-visits to already depleted ones, apparently based on his memory for the previous foraging episode about food value, location and time. Efficient use of memory allowed him to keep minimal time absent from his group while keeping food intake high. These findings support the idea that episodic-like memory offers an allpurpose solution to a wide variety of problems that require flexible, quick, yet precise decisions in situations arising from competition for food and mates in wild primates.