The magic of heat pumps, such as air conditioners or refrigerators, is the property of fluids to take up a lot of energy when boiling.

Huh?

Let's use water for an example. Modern refrigerants have properties making them a bit more difficult to calculate, but principally they work in exactly the same way.

Heating water from 10C to 20C takes up just as much heat as you get back from cooling it from 20C to 10C. Useful for a heat exchanger, but it won't run a refrigerator. But if we start with water to 95C (atmospheric pressure) and want to go to 105C, something interesting happens. From 95 to 100C it takes just as much energy per degree as we expect. But at 100C it boils. Adding more energy doesn't raise the temperature. All the added energy goes to convert water into steam. Once we have converted all the water to steam the temperature begins to rise again.

The stored energy is released if the steam is condensed back to water.

Here comes the trick: Everyone knows that water boils at a lower temperatur if you lower the pressure (e.g. if you are on top of a mountain). In an air conditioner, the pump lowers the pressure so much that the water (refrigerant) boils below room temperature. It doesn't take very much power/energy to lower the pressure and the refrigerant takes up a lot more energy from the air than is used for the pump.

On the other side of the pump, the pressure is high. The boiling point of the refrigerant is no longer below the ambient temperature, but above it. This means it doesn't want to remain like steam. I starts to condense on the walls of the vessel. This condensing releases the energy that the refrigerant picked up when it boiled.

The refrigerant is then returned to the original vessel via a valve that restricts the flow. This restriction keeps up the difference in pressure between the two sides.