Magnetospheric accretion models predict that matter from protoplanetary disks accretes onto the star via funnel flows which follow the stellar field lines and shock on the stellar surface leaving a hot spot with a density gradient. Previous work has inferred different densities in the hot spot, but has not been sensitive to the radial density distribution. Attempts have been made to measure this with X-ray observations, but X-ray emission only traces a fraction of the hot spot and also coronal emission. Here we report periodic ultraviolet and optical light curves of the accreting star GM Aur that display a time lag of about 1 day between their peaks. The periodicity arises as the source of the ultraviolet and optical emission moves into and out of view as it rotates along with the star. The time-lag indicates a difference in the spatial distribution of ultraviolet and optical brightness over the stellar surface. Within the framework of the magnetospheric accretion model, this indicates a radial density gradient in a hot spot on the stellar surface since different density parts of the hot spot are expected to emit radiation at different wavelengths. These results are the first observational confirmation of the magnetospheric accretion models prediction of a density gradient in the hot spot and demonstrate the insights gained from focusing on the wavelengths where the bulk of the accretion energy can be observed.