Quoted By:
He used Heracross which is even better for Darkrai than Infernape. Furthermore, he gave it Sleep Talk for the sole purpose of allowing it to battle through Dark Void.
The writers really only made him lose because, pardon my circular reasoning here, they didn't want him to win. Winning the pokemon league would mean that he's able to face the Elite 4 and the Champion. Defeating the Champion would pretty much make him a pokemon master, thus achieving his goal, thus bringing the saga of Ash Ketchum to an end.
Pokemon is a franchise that is still doing very well with no end in sight, so they're not about to bring an end to most important face in the series, save Pikachu.
This means that either one of the following scenarios is likely true:
1) Ash will never become a pokemon master, continuing an ever cycling journey into nowhere.
2) Ash's quest to become a pokemon master will come to an end when Pokemon as a whole ends.