Quantum controlled-Z gate for weakly interacting qubits