We propose an extension of the symmetric teleparallel gravity, in which the gravitational action L is given by an arbitrary function f of the non-metricity Q and of the trace of the matter-energy-momentum tensor T , so that L = f (Q, T). The field equations of the theory are obtained by varying the gravitational action with respect to both metric and connection. The covariant divergence of the field equations is obtained, with the geometry-matter coupling leading to the nonconservation of the energy-momentum tensor. We investigate the cosmological implications of the theory, and we obtain the cosmological evolution equations for a flat, homogeneous and isotropic geometry, which generalize the Friedmann equations of general relativity. We consider several cosmological models by imposing some simple functional forms of the function f (Q, T), corresponding to additive expressions of f (Q, T) of the form f (Q, T) = α Q + βT , f (Q, T) = α Q n+1 + βT , and f (Q, T) = −α Q −βT 2. The Hubble function, the deceleration parameter, and the matter-energy density are obtained as a function of the redshift by using analytical and numerical techniques. For all considered cases the Universe experiences an accelerating expansion, ending with a de Sitter type evolution. The theoretical predictions are also compared with the results of the standard CDM model.