I personally think it's always a bad idea to accept a counter-offer even if the only reason for your departure is money.
Most of the things that drive you to leave are unlikely to change, and if you have to quit to get the money you think you deserve, what will you have to do to get raises in the future?
I agree that the last-minute counter-offer can be way too late. (It's also pretty unfair if you've already accepted another job - I've heard of several cases of startups trying to hire people employed at larger companies who had the hire fall through due to a generous counter-offer.)