Altruistic punishment occurs when an agent incurs a cost to punish another but receives no material benefit for doing so. Despite the seeming irrationality of such behavior, humans in laboratory settings routinely pay to punish others even in anonymous, one-shot settings. Costly punishment is ubiquitous among social organisms in general and is increasingly accepted as a mechanism for the evolution of cooperation. Yet if it is true that punishment explains cooperation, the evolution of altruistic punishment remains a mystery. In a series of computer simulations I give agents the ability to punish one another while playing a continuous prisoner's dilemma. In simulations without social structure, expected behavior evolves-agents do not punish and consequently no cooperation evolves. Likewise, in simulations with social structure but no ability to punish, no cooperation evolves. However, in simulations where agents are both embedded in a social structure and have the option to inflict costly punishment, cooperation evolves quite readily. This suggests a simple and broadly applicable explanation of cooperation for social organisms that have nonrandom social structure and a predisposition to punish one another. Results with scale-free networks further suggest that nodal degree distribution plays an important role in determining whether cooperation will evolve in a structured population.