England kept their Ashes hopes alive by beating Australia by three wickets in the third Test in another nerve-shredding Headingley finale.