Magnetic fields in accretion disks play a dominant part during the star formation process but have hitherto been observationally poorly constrained. Field strengths have been inferred on T Tauri stars and possibly in the innermost part of their accretion disks, but the strength and morphology of the field in the bulk of a disk have not been observed. Spatially unresolved measurements of polarized emission (arising from elongated dust grains aligned perpendicularly to the field) imply average fields aligned with the disks. Theoretically, the fields are expected to be largely toroidal, poloidal or a mixture of the two, which imply different mechanisms for transporting angular momentum in the disks of actively accreting young stars such as HL Tau (ref. 11). Here we report resolved measurements of the polarized 1.25-millimetre continuum emission from the disk of HL Tau. The magnetic field on a scale of 80 astronomical units is coincident with the major axis (about 210 astronomical units long) of the disk. From this we conclude that the magnetic field inside the disk at this scale cannot be dominated by a vertical component, though a purely toroidal field also does not fit the data well. The unexpected morphology suggests that the role of the magnetic field in the accretion of a T Tauri star is more complex than our current theoretical understanding.