We use a near quantum limited detector to experimentally track individual quantum state trajectories of a driven qubit formed by the hybridization of a waveguide cavity and a transmon circuit. For each measured quantum coherent trajectory, we separately identify energy changes of the qubit as heat and work, and verify the first law of thermodynamics for an open quantum system. We further establish the consistency of these results by comparison with the master equation approach and the two-projective-measurement scheme, both for open and closed dynamics, with the help of a quantum feedback loop that compensates for the exchanged heat and effectively isolates the qubit.