Predicting the behaviour of others is an essential part of social cognition. Despite its ubiquity, social prediction poses a poorly understood generalization problem: we cannot assume that others will repeat past behaviour in new settings or that their future actions are entirely unrelated to the past. We demonstrate that humans solve this challenge using a structure learning mechanism that uncovers other peoples latent, unobservable motives, such as greed and risk aversion. In four studies, participants (N = 501) predicted other players decisions across four economic games, each with different social tensions (for example, Prisoners Dilemma and Stag Hunt). Participants achieved accurate social prediction by learning the stable motivational structure underlying a players changing actions across games. This motive-based abstraction enabled participants to attend to information diagnostic of the players next move and disregard irrelevant contextual cues. Participants who successfully learned anothers motives were more strategic in a subsequent competitive interaction with that player in entirely new contexts, reflecting that social structure learning supports adaptive social behaviour.