It's a completely different algorithm, surprisingly, based around "predictors" from nearby previously-decoded pixels. Quite like Floyd-Steinberg dithering.
Likewise you can turn any lossless compressor into a lossy one, by modifying the pixels that are the hardest to compress. E.g. if there is a random red pixel in a group of blue pixels, you can make it blue, and save up to 3 bytes. Or you can discard color information that humans aren't very sensitive too anyway, like JPEG does. All lossless means is that the compression isn't required by the format itself.
It is smaler than a straight to PNG file but nowhere near the size of the original JPG.
https://pngmini.com/lossypng.html
The resulting png's are much smaller. Though not necessarily as small as JPEG, it's in the same ballpark.