The Toffoli gate is a three-quantum-bit (three-qubit) operation that inverts the state of a target qubit conditioned on the state of two control qubits. It makes universal reversible classical computation possible and, together with a Hadamard gate, forms a universal set of gates in quantum computation. It is also a key element in quantum error correction schemes. The Toffoli gate has been implemented in nuclear magnetic resonance, linear optics and ion trap systems. Experiments with superconducting qubits have also shown significant progress recently: two-qubit algorithms and two-qubit process tomography have been implemented, three-qubit entangled states have been prepared, first steps towards quantum teleportation have been taken and work on quantum computing architectures has been done. Implementation of the Toffoli gate with only single- and two-qubit gates requires six controlled-NOT gates and ten single-qubit operations, and has not been realized in any system owing to current limits on coherence. Here we implement a Toffoli gate with three superconducting transmon qubits coupled to a microwave resonator. By exploiting the third energy level of the transmon qubits, we have significantly reduced the number of elementary gates needed for the implementation of the Toffoli gate, relative to that required in theoretical proposals using only two-level systems. Using full process tomography and Monte Carlo process certification, we completely characterize the Toffoli gate acting on three independent qubits, measuring a fidelity of 68.5 ± 0.5 per cent. A similar approach to realizing characteristic features of a Toffoli-class gate has been demonstrated with two qubits and a resonator and achieved a limited characterization considering only the phase fidelity. Our results reinforce the potential of macroscopic superconducting qubits for the implementation of complex quantum operations with the possibility of quantum error correction.