Shkodran Mustafi gave Arsenal the lead on 11 minutes with a powerful header from a Granit Xhaka corner.
Lacazette struck the woodwork before Joe Bennett crossed for Víctor Camarasa to turn and fire in the equaliser just before the break.
Pierre-Emerick Aubameyang's superb curling shot put Arsenal ahead on 62 minutes but Danny Ward's header eight minutes later made the score 2-2.
In the 81st minute, Lacazette thundered his effort beyond Neil Etheridge at the near post as Arsenal won for the second successive match.
Defeat moves Cardiff down to 16th on two points, while Arsenal are ninth with six points.
Cardiff: 15 Sep v Chelsea (A)
Arsenal: 15 Sep v Newcastle (A)