Abstract. The obstacle problem associated with p-harmonic functions is extended to unbounded open sets, whose complement has positive capacity, in the setting of a proper metric measure space supporting a (p, p)-Poincaré inequality, 1 < p < ∞, and the existence of a unique solution is proved. Furthermore, if the measure is doubling, then it is shown that a continuous obstacle implies that the solution is continuous, and moreover p-harmonic in the set where it does not touch the obstacle. This includes, as a special case, the solution of the Dirichlet problem for p-harmonic functions with Sobolev type boundary data.