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.
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