Dani Martinez won the Criterium du Dauphine after a thrilling final stage, with Thibaut Pinot finishing as runner-up.