The invaded cluster algorithm is used to study the XY model in two and three dimensions up to sizes 20002 and 1203, respectively. A soft spin O(2) model, in the same universality class as the three-dimensional XY model, is also studied. The static critical properties of the model and the dynamical properties of the algorithm are reported. The results are Kc=0.45412(2) for the three-dimensional XY model and η=0.037(2) for the three-dimensional XY universality class. For the two-dimensional XY model the results are Kc=1.120(1) and η=0.251(5). The invaded cluster algorithm does not show any critical slowing for the magnetization or critical temperature estimator for the two-dimensional or three-dimensional XY models.