Piracy off the coast of Somalia took the world by surprise when, within a six-year span (2005-2011), as many as 1,099 ships were attacked, among which more than 200 were successfully hijacked. In 2012 however, attacks had plummeted with no new hijacking reported between 2013 and mid-2015. We quantitatively investigate the roles of two crime deterrence measures widely believed to be responsible for the collapse of Somali piracy: the deployment of international navies in pirate-infested waters and the provision of armed security guards onboard vessels. Using unique data on attacks, hijacks, and ransoms to estimate a structural model of Somali piracy, we estimate the elasticity of crime with respect to deterrence and highlight the positive and negative spillovers generated by the private adoption of onboard armed security. We discuss counterfactual scenarios obtained by varying the intensity and composition of deterrence measures.