The folk theorem tells us that a wide range of payoffs can be sustained as equilibria in an infinitely repeated game. Existing results about learning in repeated games suggest that players may converge to an equilibrium, but do not address selection between equilibria. I propose a stochastic learning rule that selects a subgame-perfect equilibrium of the repeated game in which payoffs are efficient. The exact payoffs selected depend on how players experiment; two natural specifications yield the Kalai-Smorodinsky and maxmin bargaining solutions, respectively. (c) 2022 The Author(s). Published by Elsevier Inc. This is an open access article under the CC BY license (http://creativecommons.org/licenses/by/4.0/).