1590s, "engine of war consisting of a small, attachable bomb used to blow in doors and gates and breach walls," from French pétard (late 16c.), from Middle French péter "break wind," from Old French pet "a fart," from Latin peditum, noun use of neuter past participle of pedere "to break wind," from PIE root *pezd- "to fart" (see feisty). Surviving in figurative phrase hoist with one's own petard (or some variant) "caught in one's own trap, involved in the danger one meant for others," literally "blown up with one's own bomb," which is ultimately from Shakespeare (1605):
For tis the sport to haue the enginer Hoist with his owne petar ["Hamlet" III.iv.207].
For the verb, see hoist. The thing itself was rendered obsolete by the development of bombs; it seems to have had a reputation for backfiring. Related: Petardier.