Context. The first soft gamma-ray repeater was discovered over three decades ago, and was subsequently identified as a magnetar, a class of highly magnetised neutron star. It has been hypothesised that these stars power some of the brightest supernovae known, and that they may form the central engines of some long duration gamma-ray bursts. However there is currently no consenus on the formation channel(s) of these objects. Aims. The presence of a magnetar in the starburst cluster Westerlund 1 implies a progenitor with a mass ≥40 M , which favours its formation in a binary that was disrupted at supernova. To test this hypothesis we conducted a search for the putative pre-SN companion.Methods. This was accomplished via a radial velocity survey to identify high-velocity runaways, with subsequent non-LTE model atmosphere analysis of the resultant candidate, Wd1-5. Results. Wd1-5 closely resembles the primaries in the short-period binaries, Wd1-13 and 44, suggesting a similar evolutionary history, although it currently appears single. It is overluminous for its spectroscopic mass and we find evidence of He-and N-enrichement, O-depletion, and critically C-enrichment, a combination of properties that is difficult to explain under single star evolutionary paradigms. We infer a pre-SN history for Wd1-5 which supposes an initial close binary comprising two stars of comparable (∼41 M + 35 M ) masses. Efficient mass transfer from the initially more massive component leads to the mass-gainer evolving more rapidly, initiating luminous blue variable/common envelope evolution. Reverse, wind-driven mass transfer during its subsequent WC Wolf-Rayet phase leads to the carbon pollution of Wd1-5, before a type Ibc supernova disrupts the binary system. Under the assumption of a physical association between Wd1-5 and J1647-45, the secondary is identified as the magnetar progenitor; its common envelope evolutionary phase prevents spin-down of its core prior to SN and the seed magnetic field for the magnetar forms either in this phase or during the earlier episode of mass transfer in which it was spun-up. Conclusions. Our results suggest that binarity is a key ingredient in the formation of at least a subset of magnetars by preventing spin-down via core-coupling and potentially generating a seed magnetic field. The apparent formation of a magnetar in a Type Ibc supernova is consistent with recent suggestions that superluminous Type Ibc supernovae are powered by the rapid spin-down of these objects.