The Purkinje system is part of the fast-conducting ventricular excitation system. The anatomy of the Purkinje system varies from person to person and imposes a unique excitation pattern on the ventricular myocardium, which defines the morphology of the QRS complex of the ECG to a large degree. While it cannot be imaged in-vivo, it plays an important role for personalizing computer simulations of cardiac electrophysiology. Here, we present a new method to automatically model and customize the Purkinje system based on the measured electrocardiogram (ECG) of a patient. A graphbased algorithm was developed to generate Purkinje systems based on the parameters fibre density, minimal distance from the atrium, conduction velocity, and position and timing of excitation sources mimicking the bundle branches. Based on the resulting stimulation profile, the activation times of the ventricles were calculated using the fast marching approach. Predescribed action potentials and a finite element lead field matrix were employed to obtain surface ECG signals. The root mean square error (RMSE) between the simulated and measured QRS complexes of the ECGs was used as cost function to perform optimization of the Purkinje parameters. One complete evaluation from Purkinje tree generation to the simulated ECG could be computed in about 10 seconds on a standard desktop computer. The measured ECG of the patient used to build the anatomical model was matched via parallel simplex optimization with a remaining RMSE of 4.05 mV in about 16 hours. The approach presented here allows to tailor the structure of the Purkinje system through the measured ECG in a patient-specific way. The computationally efficient implementation facilitates global optimization.