Given the circumstances, it seems highly unlikely that Bill would be prosecuted under any law for briefly holding the gun. (Of course, it would be another matter if he subsequently kept the gun.)
If he were investigated or prosecuted for an offence related to holding the gun, the defence of necessity is available as a general defence. If Bill is accused of an offence related to holding the gun, he mayBob may say that, given the circumstances, it was justifiably necessary to commit the offence because of the consequences to him if he hadn't (consequences such as hishis serious injury or death, caused by Bob).
A common example is two mountain-climbers joined by rope, one of them falls and the other is put in the position of having to choose between (a) cutting the rope to save herself thereby killing her companion or (b) to die with her companion.
To paraphrase R v Conway [1989] Q.B. 290:
the defendant was constrained by circumstances to do as he did to avoid death or serious bodily harm to himself.