The episode of Pokemon you might be thinking of is called 'Memories are Made of Bliss!' The original Japanese title for this story is 'Memories are Pearls! Friendship is a Diamond!'
This episode was the final in the 'Diamond and Pearl' Pokemon series and was first shown in the USA in February 2011.The handshake comes as Ash, with his friend Brock, say farewell to their friend Dawn before setting off for their homes in Kanto by catching a ferry. Dawn has thanked her two friends for all they have taught her through their adventures together. Ash and Brock, soon to go their separate ways themselves, reply that it is Dawn who has taught them so much, and thank her for her friendship.
High-Fives and Handshakes
Although Ash and Dawn do not shake hands, they do high-five each other, as they often did in the Diamond and Pearls series. It is Ash and Brock who shakes hands, when they part company at the end of the episode for Pewter City and Pallet Town respectively.
Here's one YouTube user's musical tribute to Ash and Dawn: