Yevamot 54 - How to do yibum
One who decides to do a yibum - that is, to cohabit with the wife of his deceased brother who died without children ("yevamah") - can do it in any of the following ways. Whether done willingly for the purpose of a mitzvah or by coercion or by mistake, whether he only begins the act or completes it, and whether it is a natural or anal intercourse - it makes no difference, and he acquires her as a wife.
How can a man be coerced? Could it be that idolaters forced him? - No, this explanation won't stand: since his member was erect, it must be that he found the situation somewhat desirable, and was therefore a willing participant. (This rule is called "Erection is a state of mind.") Can we suggest that he was sleeping? - No, for then he lacks the intelligence to effect legal acquisition. Can we then suggest he was on a roof with erection for his wife, fell off the roof and accidentally inserted into his yevamah? - That too does not stand: he may be liable for damages, such as pain and medical bills, but he does not effect a yibum. Final conclusion: he had erection for his wife, and then the brother's wife seized him and cohabited with him.
Incidentally, if a man intends to insert his member into a wall and accidentally inserts it in his yevamah, he has not acquired her as a wife, since his intention was not for cohabitation; however, if he intended to insert it into an animal, and inserted it into his yevamah, he has acquired her, because an act with an animal is considered legally a form of cohabitation.
Art: The Sisters by George Baxter