World number eight Rafael Nadal is out of the US Open after losing a five-set, third-round thriller to Italian Fabio Fognini at Flushing Meadows.