Ben Stokes scored a remarkable unbeaten 135 to give England a dramatic one-wicket victory in the third Ashes Test.