Heat always flows from a high temperature to a low temperature. However, we want heat to go the opposite way (i.e. from the cold outside to our warm houses). There's a technique to do this. We use a gas (the refrigerant) to transfer heat.
We first expand the gas (which cools it) until it cools below the cold outside. We then bring it near the cold outside where it now starts absorbing heat until it matches the cold outside temperature. We then move the gas and compress it until it's temperature matches/exceeds our desired warm inside temperature. Then, we bring it to the warm indoors where heat will now flow out of it.
During the entire cycle, the gas is inside a closed loop. It exchanges heat through radiators. The compression & expansion cycles uses energy (technically they can be offset against each other a bit) which is added to the gas (conservation of energy) raising its temperature.
Thus by supplying a little electricity, we're able to move heat from the cold outdoors to the warm indoors. The high efficiencies are because for using X units of energy, we're able to heat the house by X+Y units where Y is the heat transferred from the outside. Typically Y >> X.