Just because the other guy got the job doesn't automatically mean that you were a bad candidate.

I have learned that superior job-specific skills and time in position don't always correlate to getting the job.

There are just so many other reasons that could be in the mix here, many of which the boss could never admit to.

Do the boss and the new guy have anything in common? Maybe, their children go to the same school? Maybe, they met at a racquetball court. Culinary school.

So, maybe, you will get the job next time. I'd be updating my resume and looking for another job also (just in case), but don't mess up the next opportunity with your current employer.

By the way, sometimes our feelings have a way of carrying on our face without us realizing it. You will need to pay very close attention to how others are perceiving your new role. Don't let the cat out of the bag.