A Jake brake works by opening the exhaust valves when the engine's piston reaches top dead center of the compression stroke. The engine uses its momentum and energy to compress the air, and that energy is lost to the atmosphere when the exhaust valves are opened.
A spark ignition engine uses a throttle plate to control the amount of air entering the engine. When the driver lifts his foot off the gas, the engine is forced to draw air through a closed throttle plate, which requires work and thus slows the engine. A diesel engine has no restrictions to its airflow and cannot slow down the same way. Although work is used to compress the intake air, the compressed air springs back against the piston after the top of the compression stroke. This causes all the work used to compress the air to be put back into pushing the piston down, completing the rotation of the crankshaft and causing the engine to keep its momentum. Although this is useful for efficiency, as no fuel is used to maintain the engine's speed, it is undesirable when trying to slow down. By opening the exhaust valves at the top of the compression stroke, using a Jake brake, the work done compressing the air is lost to the atmosphere and thus the engine slows down.