It is possible that ultrahigh energy cosmic rays (UHECRs) are generated by active galactic nuclei (AGNs), but there is currently no conclusive evidence for this hypothesis. Several reports of correlations between the arrival directions of UHECRs and the positions of nearby AGNs have been made, the strongest detection coming from a sample of 27 UHECRs detected by the Pierre Auger Observatory (PAO). However, the PAO results were based on a statistical methodology that not only ignored some relevant information (most obviously the UHECR arrival energies, but also some of the information in the arrival directions), but also involved some problematic fine-tuning of the correlation parameters. Here we present a fully Bayesian analysis of the PAO data (collected before 2007 September), which makes use of more of the available information, and find that a fraction FAGN= 0.15+0.10−0.07 of the UHECRs originate from known AGNs in the Veron-Cetty and Veron (VCV) catalogue. The hypothesis that all the UHECRs come from VCV AGNs is ruled out, although there remains a small possibility that the PAO–AGN correlation is coincidental (FAGN= 0.15 is 200 times as probable as FAGN= 0.00).