Sebastian Vettel snatched pole position off Lewis Hamilton in a thrilling Canadian GP qualifying, delivering a much-needed result for Ferrari.