Well they both work on compression, diesels simply rely on it more than gasoline engines.
Diesel engines work on what's called adiabatic compression heating. In other words, the compression causes the air to heat to a point higher than the ignition point of the fuel. Diesel engines usually use glow plugs to compensate for the lack of adiabatic compression heating when the engine is cold.