Lee Evans scored the magnificent winning goal that this pulsating thriller at the DW Stadium deserved.
Latics fell behind on the 20-minute mark through Joe Ralls, who was perhaps fortunate to still be on the field after catching Evans with an awful lunge in the early exchanges.
But that was only a teaser of the drama that was to come.
Josh Windass won - and then missed - a penalty for Latics three minutes into the second period.
The forward made partial amends on the hour mark when his free-kick deflected into the path of Michael Jacobs, who tucked home the equaliser.
Windass then put Latics ahead three minutes later with a cracking finish just inside the far post.
But back came Cardiff, and former Latics striker Omar Bogle levelled 20 minutes from time within moments of coming on.
Still there was to be one more twist, though, and it came when Evans cut in from the left and unleashed an unstoppable strike that flew into the top corner.