The ever increasing performance of supercomputers is now enabling kinetic simulations of extreme astrophysical and laser produced plasmas. Three-dimensional particle-in-cell (PIC) simulations of relativistic shocks have revealed highly filamented spatial structures and their ability to accelerate particles to ultrarelativistic speeds. However, these PIC simulations have not yet revealed mechanisms that could produce particles with tera-electron volt energies and beyond. In this work, PIC simulations in one dimension (1D) of the foreshock region of an internal shock in a gamma ray burst are performed to address this issue. The large spatiotemporal range accessible to a 1D simulation enables the self-consistent evolution of proton phase space structures that can accelerate particles to giga-electron volt energies in the jet frame of reference, and to tens of tera-electron volt in the Earth’s frame of reference. One potential source of ultrahigh energy cosmic rays may thus be the thermalization of relativistically moving plasma.