diesels can operate hotter than petrol engines, since they don’t pre-detonate like petrols do at high operating temps (pinking, iirc). bigger temp drop for the heat cycle means better inherent efficiency.
Diesels can knock, though direct injection has helped prevent that (by ensuring fuel is only present when combustion is desired, unlike older injection methods).
One of the other reasons D’s are more efficient is they don’t have a throttle, immidiately offering up a greater efficiency especially around idle and lower revs.