If your company uses competency questions and a ranking system in interviews, as many do, internal candidates can really lose out.
This is because you go into the interview knowing the people who are interviewing you, knowing they know you, and so you assume that they will draw on that knowledge of you when making the hiring decision. So you often don't mention that big project you did or all the support you've been giving to the more junior members of your team because you know the interviewer already knows that. Internal candidates therefore tend to give less detailed answers and to be less specific about their experiences and achievements, and even though the interviewees may know full well you have the competencies they're ranking, if you don't explicitly say it, they can't score you for it.
Then the external candidates come in and give a brilliant interview that ticks off the competency boxes - and they get the job over you because on paper they're better. Even if the hiring interviewer knows you'd be brilliant for the job, HR wouldn't let them give it to you if the paperwork shows you rank lower than the other candidate.
It's not fair, but it's how things work these days.
See your manager and get the feedback. It may well be that you didn't interview very well and there's some really simple techniques you could learn to improve for the next time there's an opportunity. The company has to be fair to all candidates who apply and they can't favour you just because you're internal and a known entity.
If the feedback you receive is vague or unhelpful and you feel that you've been shafted, then at that point, I'd be looking elsewhere.
However, for now, I'd chalk it up to experience, hear what my manager had to say, and be open-minded about the fact that perhaps after only three years there is still more I can learn in my current role before getting promoted. If you really enjoy your work and love your team, I wouldn't throw the baby out with the bathwater just yet.
I'm sorry for your disappointment - I've been there and I know it hurts.