Why does a gas get hotter when it's compressed? Watch this animation to find out: remember temperature is just a measure of the energy per molecule, kinetic energy in this case. The compressing moving piston speeds up the atom!
A Bit More Explanation...
In this very simple model of a gas, a single atom bounces elastically in a cylinder. It will continue to bounce at the same speed forever if the piston does not move. If we start the piston compressing, the atom gains speed when it bounces off the moving piston.
(speed after collision) = (speed before)+2*(piston speed).
That alone is enough to explain why a gas heats when we compress it and cools as we allow it to expand.
Game: Using the slider and pause button the right way, you can (almost?) stop the ball moving. Why can't you use a similar trick to really cool a gas?
Here's the relevant lecture.
Michael Fowler and Qian Xiong, University of Virginia