We have studied relaxation in the Coulomb glass from a nonequilibrium state arising due to an abrupt change of the electron density. Our results are of relevance to some recent experiments on doped and amorphous semiconductors using metal-oxide-semiconductor field-effect transistor geometry, in which the relaxation of conductivity has been studied under changes of the gate voltage. By solving the time-dependent equation for the density of states, we have obtained some important features of how the Coulomb gap develops under these conditions. We also present the implications of our results on the relaxation of conductivity.