Quasiharmonic functions correspond to p-harmonic functions when minimizers of the p-Dirichlet integral are replaced by quasiminimizers. In this paper, boundary regularity for quasiharmonic functions is characterized in several ways; in particular it is shown that regularity is a local property of the boundary. For these characterizations we employ a version of the so called pasting lemma; this is a useful tool in the theory of superharmonic functions and our version extends the classical pasting lemma to quasiharmonic functions and quasiminimizers. The results are obtained for metric measure spaces, but they are new also in the Euclidean spaces.