when the piston is compressed suddenly , it is done adiabatically (dQ=0).
thus when the volume suddenly decreases, the temp and pressure rise considerably.
thus heat is developed in the system.
after some time , the gas loses the heat to the surroundings and thus the temp. and press. of the gas decreases.