We consider a fault containing two regions with different mechanical behaviours: a strong, velocity-weakening region (asperity) and a weak, velocity-strengthening region. The fault is embedded in a shear zone subject to a constant strain rate by the motions of adjacent tectonic plates. The fault is modelled as a discrete dynamical system whose state is described by two variables expressing the slip deficits of the two regions. Because of plate motion, the asperity accumulates stress and eventually releases it, producing an earthquake, when a frictional threshold is exceeded. The weak region is subject to a very slow creep during interseismic intervals and may slip at a higher rate (afterslip) as a consequence of coseismic stress imposed by the asperity failure. The evolution equations of the system are solved analytically for the interseismic intervals, the asperity slip and the afterslip in the weak region. It is found that the amount of afterslip is proportional to the seismic slip of the asperity, in agreement with observations. The model shows that afterslip is a natural consequence of seismic slip in a fault containing a velocity-strengthening region. Afterslip may have any duration, according to the intensity of velocity strengthening, thus accounting for the wide range of observed durations. The model is applied to the fault of the 2011 Tohoku-Oki earthquake. The results suggest that the first four months after the event were dominated by afterslip, while the subsequent postseismic deformation was probably due to viscoelastic relaxation in the asthenosphere.