We analyze the implementation of a fast nonadiabatic CZ gate between two transmon qubits with tunable coupling. The gate control method is based on a theory of dynamical invariants which leads to reduced leakage and robustness against decoherence. The gate is based on a description of the resonance between the 11 and 20 using an effective Hamiltonian with the six lowest energy states. A modification of the protocol allows us to take into account the higher-order perturbative corrections of this effective model. This enables a gate fidelity several orders of magnitude higher than other quasiadiabatic protocols, with gate times that approach the theoretical limit.