Iran raised the stakes in its standoff with the U.S. and Europe on Thursday, warning that if the 2015 nuclear agreement unravels, it would follow the path of North Korea and quit a treaty aimed at stopping the spread of nuclear weapons.

The threat, voiced by an Iranian official to reporters, marked the first time Tehran has explicitly used its participation in the Nuclear Non-Proliferation Treaty, or NPT, as leverage in its talks with European officials over keeping its commitments in the separate 2015 deal. Iran ratified...