We present a three-dimensional simulation of the ion dynamics in an electron cyclotron resonance ion source. Ion trajectories in the min-B field of the source are calculated taking ion-ion and electron-ion collisions into account. The electrons are not tracked but considered as a neutralizing background with a Maxwell-Boltzmann velocity distribution. Some applications of the code are discussed, e.g., the calculated charge-state and phase-space distributions of extracted ion beams and the ionization dynamics in the plasma.