In this paper, I investigate the issue of the contingency and inevitability of science. First, I point out valuable insights from the existing discussion about the issue. I then formulate a general framework, built on the notion of contrastive explanation and counterfactuals, that can be used to approach questions of contingency of science. I argue, with an example from the existing historiography of science, that this framework could be useful to historians of science. Finally, I argue that this framework shows the existing views on historical contingency and counterfactuals in a new light. The framework also shows the value of existing historiography in philosophical debates.