"Hoist with his own petard" is a phrase from a speech in William Shakespeare's play Hamlet that has become proverbial. The phrase's meaning is that a bomb-maker is blown ("hoist", the past tense of "hoise") off the ground by his own bomb ("petard"), and indicates an ironic reversal or poetic justice.
 In modern vernacular usage of the idiom, the preposition "with" is commonly exchanged for a different preposition, particularly "by" (i.e. "hoist by his own petard"). The latter form is recognized by many British and American English dictionaries as an interchangeable alternative. Prepositions other than "by" and the original "with" are not widely accepted and may be seen as erroneous or even nonsensical in the correct context of the phrase.
 The phrase occurs in Hamlet act 3, scene 4, as a part of one of Hamlet's speeches in the Closet Scene. Hamlet has been acting mad to throw off suspicion that he is aware that his uncle, Claudius, has murdered his father and married his mother, Queen Gertrude, in order to usurp the throne. In the Closet Scene, Polonius, at Claudius' behest, has hidden himself behind an arras in Gertrude's chambers to listen in as Gertrude scolds Hamlet for his mad antics, hoping to determine whether he is truly mad or merely pretending. On revealing his presence, Hamlet kills him thinking him to be Claudius. Hamlet then accuses Gertrude of complicity in his father's murder, but when she protests her innocence, the two of them begin to conspire to reveal Claudius's guilt.
 Having previously been ordered to travel to England on a pretext, accompanied by Rosencrantz and Guildenstern carrying letters to the King of England, Hamlet tells his mother:
 There's letters sealed; and my two schoolfellows,
Whom I will trust as I will adders fanged,
They bear the mandate; they must sweep my way
And marshal me to knavery. Let it work,
For 'tis the sport to have the enginer
Hoist with his own petard; and 't shall go hard
But I will delve one yard below their mines
And blow them at the moon. O, 'tis most sweet
When in one line two crafts directly meet.
 The letters contain a request from King Claudius to the King of England to have Prince Hamlet killed, but Hamlet manages to modify them during the journey so that they instead request the deaths of Rosencrantz and Guildenstern. Hamlet is thus able to return to Denmark in secret to seek his revenge.
 Hamlet exists in several early versions: the first quarto edition (Q1, 1603), the second quarto (Q2, 1604), and the First Folio (F, 1623). Q1 and F do not contain this speech, although both include a form of The Closet Scene, so the 1604 Q2 is the only early source for the quote.
 The omission of this speech—as well as the long soliloquy in act 4, scene 4{{efn|The "How all occasions do inform against me" soliloquy which is at act 4, scene 4, lines 34–69.—is generally considered to have been done in the playhouse for various practical reasons. But in the 1985 Cambridge Shakespeare edition of the play, Philip Edwards argued that these were deliberate cuts by Shakespeare. For Hamlet, famously procrastinating about his revenge, to suddenly show such resolve and a concrete plan to do away with Rosencrantz and Guildenstern is out of character, and, as the plan outlined is what ends up happening in the play, the speech gives away the plot and lessens the suspense. It is also a plot hole in that Hamlet, at this point in the play, has no way of actually knowing that Claudius plans to have him killed in England, nor even that Rosencrantz and Guildenstern are to be his travelling companions. The audience is aware that Rosencrantz and Guildenstern are to be his companions, as they have seen Claudius instructing them so at the beginning of act 3, scene 3, but the plot to have him killed is otherwise not discussed until act 4, scene 3.
 G.R. Hibbard, in The Oxford Shakespeare edition, agrees with Edwards that the omission of the speech increases the suspense in the F version. However, Ann Thompson and Neil Taylor, in The Arden Shakespeare third series edition, point out that Hamlet is not specifically planning to kill Rosencrantz and Guildenstern, he merely resolves to outwit them. For example, in the 1964 film adaptation by Grigori Kozintsev the speech is moved to the (later) point in the film where Hamlet describes how he outwitted Rosencrantz and Guildenstern.
 The word "hoist" here is the past participle of the now-archaic verb hoise (since Shakespeare's time, hoist has become the present tense of the verb, with hoisted the past participle), and carries the meaning "to lift and remove".
 A "petard" is a "small bomb used to blow in doors and breach walls" and comes from the French pétard, which, through Middle French (péter) and Old French (pet), ultimately comes from the Latin pedere ("to break wind") or, much more commonly, the slang form "to fart". Although Shakespeare's audiences were probably not familiar with the origin of the word, the related French word petarade was in common use in English by the 17th century meaning "gun shot of farting" making it appear likely that the double meaning was intended by Shakespeare as a joke.
 "Enginer", although the origin of the modern engineer, had the meaning specifically of a military engineer or a sapper: someone who works with military engines (mines, grenades, siege engines). The word should be pronounced with the stress on the first syllable.
 The phrase itself is a variation on two earlier proverbial expressions: "The fowler is caught in his own net" and "To beat one at his own weapon".
 The "letters" referred to in the first line are the letters from Claudius to the King of England with the request to have Hamlet killed, and the "schoolfellows" are Rosencrantz and Guildenstern who went to school with Hamlet at Wittenberg. Hamlet says he will trust them as "adders fanged", that is as much as one would trust a pair of venomous snakes. That they "bear the mandate"—carry the letters of the diplomatic mission to England—is in itself suspicious according to Hibbard: such letters would usually be carried by the most senior member, Hamlet, rather than the two underlings. Thompson and Taylor disagree, as it might simply mean that Rosencrantz and Guildenstern have been ordered by Claudius to go. That they "must sweep my way" means that they must prepare the way for Hamlet, and the way they "sweep" is to "marshal [him] to knavery": conduct him to some kind of trick, villainy, or trap. The word "marshal" here begins a string of military metaphors: Hamlet sees his contest of wits with Rosencrantz and Guildenstern in terms of siege warfare. Hamlet's response is to say "Let it work"; to let their plan unfold.
 His resolve in the fifth and sixth lines—continuing the military metaphor—is to have them blown up with their own bomb that they had intended for him. Unless it "shall go hard"—unless he has very bad luck—he will "delve [...] below their mines / And blow them at the moon." Mines here are the tunnels used in siege warfare to attack a fortified town, and later the explosives used in such tunnels. In the last two lines he savours the competition of two practitioners of cunning and schemes meeting head on, continuing the martial metaphor of mining and counter-mining.
 The Criminals are not only brought to execution, but they are taken in their own Toyls, their own Stratagems recoyl upon 'em, and they are involv'd them selves in that mischief and ruine, which they had projected for Hamlet. The speech is a central exemplar of a general theme or pattern in Hamlet: ironic reversal. Throughout the play the pattern unfolds repeatedly: his enemies employ a stratagem against Hamlet, but fail, and he then turns the stratagem back on them. For instance, when verbally sparring with Claudius in act 1, scene 2, Hamlet turns his own words back against him:
 Claudius: But now, my cousin Hamlet and my son—Hamlet: A little more than kin and less than kind.Claudius: How is it that the clouds still hang on you?Hamlet: Not so, my lord; I am too much in the sun.
 When Claudius invokes their kinship, Hamlet puns on kin—kind; and when Claudius invokes a weather metaphor for a gloomy disposition, Hamlet's counter has three distinct meanings: literally that he is not under a cloud but actually too much in the sun; that Claudius' constant invocation of "son" (which Hamlet puns as "sun") is getting wearisome; and that he feels he spends too much time in the presence of the king ("the sun"). Similarly in the Closet Scene:
 Gertrude: Hamlet, thou hast thy father much offended.Hamlet: Mother, you have my father much offended.Gertrude: Come, come, you answer with an idle tongue.Hamlet: Go, go, you question with a wicked tongue.
 For each verbal attack by Gertrude, Hamlet counters by turning her own words back at her. The plotters' plan was to have Gertrude, his mother, scold him for his antics while Polonius listened from hiding, in the hopes of learning whether Hamlet is truly mad or merely pretending. Instead the conversation ends with Polonius dead and Gertrude convinced of Claudius' guilt and her culpability.
 To catch out Hamlet, Claudius and Polonius have Ophelia put on a show for him; whereas Hamlet uses the play-within-the-play The Mousetrap to "catch the conscience of the king". When Claudius plans to ship Hamlet off to be killed in England, Hamlet manages to thwart him and returns in a larger pirate ship. Rosencrantz and Guildenstern are to deliver a letter requesting Hamlet's death but Hamlet swaps it for one that requests Rosencrantz and Guildenstern's deaths.
 In the final scene, Laertes applies poison to his rapier to kill Hamlet, but Hamlet ends up killing Laertes with it. In the end, he kills Claudius with the rapier and poisoned wine that were Claudius's intended weapons against Hamlet.
 Ironic reversal was well-known in sixteenth-century England and Elizabethan theatre inherited the tradition from Latin comedy and Christian thought. It was so common as to constitute convention and an early example is from The Jew of Malta (1589–90): Barabas the Jew lays a trap involving a collapsing floor but falls through it and lands in a cauldron he had prepared for stewing Turks. In "Ironic Reversal in Hamlet" (1966), Thomas F. Van Laan wrote that even further than the general Elizabethan dramatic convention, in Hamlet it is "… central and substantive. It lies at the heart of the play's mystery; it constitutes, in fact, a portion of that mystery".
 A central critical question in Hamlet is the degree to which Hamlet hesitates and procrastinates, or whether he is coldly determining Claudius's guilt and waiting for an opportunity to exact his revenge. One pivotal point in this question is the "Hoist with his own petard" speech: does it indicate merely that Hamlet suspects the plot against him and means to be on guard, or does it indicate that he has already planned a counter to it? In 1870, George Henry Miles published "A Review of Hamlet" in which he argued that the pirates that attack Hamlet's ship on the way to England, and on which he escapes and returns to Denmark, was not a chance encounter but rather a counter-plot planned ahead of time by Hamlet himself. According to Miles', the "Hoist with his own petard" speech is indicative of premeditation from Hamlet: it outlines future events and these are what actually turn out to take place. He particularly rests his argument on the "When in one line two crafts directly meet" line, seeing in it a pun on "crafts" (stratagems and ships) indicating that Hamlet knows in advance that the two ships will encounter each other on the journey.
 William Witherle Lawrence, writing in 1944, dismissed the idea: "Little time need be wasted on the absurd idea that the pirate attack was not accidental, but planned by Hamlet." Writing in 1975, Martin Stevens attempted to revive the idea, but most critics who have addressed the issue have sided with Lawrence. However, their main argument against the idea has been based on the idea that the meaning of the word "craft" to mean "ship" was not in use until 1671, based on the Oxford English Dictionary entry's earliest dating for the word. In 1999 David Farley-Hills published an article in The Review of English Studies demonstrating that the relevant meaning was attested as early as 1450. He goes on to make an argument that the pirates were in collusion with Hamlet, and the attack a part of his plan already in mind during the speech in act 3, scene 4.