The sense of "guarding from attack" goes back to early medieval times; but it grew up alongside another, more active sense of "warding off an attack", which has not survived. It was active in Shakespeare's time, though, especially conveying the notion of divine prohibition. Several characters in the plays ask God to defend something. When Mowbray takes his oath in Richard II (I.iii.18), he says: "Which God defend a knight should violate!"
This is asking God to forbid any violation, not to help it happen. The same meaning applies when Othello exclaims: "heaven defend your good souls that you think I will your serious and great business scant" (Othello, I.iii.263). Any deity can be approached. Charmian in Antony and Cleopatra (III.iii.42) calls on her goddess in the same way. "Hath he seen majesty?", she asks of the Messenger. "Isis else defend".
David Crystal is author, with Ben Crystal, of Shakespeare's Words, published by Penguin