Deus ex machina is a literary device in which a seemingly unsolvable problem is suddenly and unexpectedly resolved by an outside force or event. In Twelfth Night, this device is used in the form of a letter that reveals the true identity of Sebastian, Viola's twin brother, who was presumed to have died in a shipwreck at the beginning of the play. The letter, which is written by Antonio, Sebastian's friend, arrives at a crucial moment in the plot, just as Viola is about to be forced into an unwanted marriage with Sir Andrew Aguecheek. The revelation of Sebastian's survival not only resolves the conflict between Viola and Sir Andrew, but also sets the stage for the play's happy ending.
Shakespeare's use of deus ex machina in Twelfth Night has been the subject of much critical debate. Some critics argue that the device is a cheap and artificial way to resolve the plot, while others argue that it is a necessary and effective way to bring the play to a satisfying conclusion. Ultimately, the use of deus ex machina is a matter of personal taste, and each reader must decide for themselves whether or not they find it to be an acceptable plot device.