Aims. Early rebrightenings at a post-burst time of 10 2 -10 4 s have been observed in the afterglows of some gamma-ray bursts (GRBs). Unlike X-ray flares, these rebrightenings usually last for a comparatively long period. The continuous energy injection mechanism can usually only produce a plateau in the afterglow light curve, but not a rebrightening. Also, a sudden energy injection can induce a rebrightening, but the rebrightening is slightly too rapid. Methods. We argue that the early rebrightenings can be produced by a ring-shaped jet, for which we here present a model. In this scenario, the GRB outflow is not a full cone, but a centrally hollowed ring. Assuming that the line of sight is on the central symmetry axis of the hollow cone, we calculate the dynamical evolution of the outflows and the multiband afterglow light curves. Results. We find that the early rebrightenings observed in the afterglows of some GRBs (i.e. approximately 1% of Swift events), such as GRB 051016B, 060109, 070103, and 070208, can be reproduced with this model. Conclusions. We suggest that these long-lasting early rebrightenings in GRB afterglows are the result of ring-shaped jets.