Statecharts and Petri nets are two popular visual formalisms for modelling complex systems that exhibit concurrency. Both formalisms are supported by various design tools. To enable the automated exchange of models between Petri net and statechart tools, we present a structural, polynomial algorithm that translates safe Petri nets into statecharts. The translation algorithm preserves both the structure and the behaviour of the input net. The algorithm can fail, since not every safe net has a statechart translation that preserves both its structure and behaviour. The algorithm is proven correct and the class of safe nets for which the algorithm succeeds is formally characterised. We show that the algorithm can also fail for some nets that do have a structure- and behaviour-preserving statechart translation, but this incompleteness does not appear to be a severe limitation in practice.