We propose a variational model for artifact-free JPEG decompression. It is based on the minimization of the total variation over the convex set U of all possible source images associated with given JPEG data. The general case where U represents a pointwise restriction with respect to an L-orthonormal basis is considered. Analysis of the infinite dimensional model is presented, including the derivation of optimality conditions. A discretized version is solved using a primal-dual algorithm supplemented by a primal-dual gap-based stopping criterion. Experiments illustrate the effect of the model. Good reconstruction quality is obtained even for highly compressed images, while a graphics processing unit (GPU) implementation is shown to significantly reduce computation time, making the model suitable for real-time applications.