Boys do tend to have harder time with this and the littler they are the harder it is to get it right every time-or even anytime.
It sounds like his brain is just not getting the message until "right before" or else he is too busy to stop if he does get the message early. Both are a symptom of his age and will clear up over time. At this stage you don't want a battle over the bathroom.
Switch back to pull ups if it makes your life easier it won't make a difference unless he cares.
But start a reminder service for him-every hour or so just check in with him-see if it helps.
If he does go when you remind him and it stops then you know he was too interested to stop and go-there are much more important things in his life than the bathroom even if you don't think so.
If it doesn't help then it's probably an under developed trigger feeling that should fix itself as he grows. If you're still having this problem at age 5 bring it up with his doctor.
Welcome to the wonderful world of boys, for some reason hygene is a boy battle until their like 95.
Good Luck.