Internalizing the beat in non-trivial situations is actually one of the most difficult things that a musician has to acquire.
It's also seen that different individuals develop different internal strategies to achieve that. For example, some people say they feel the beat as a pulse in their stomach, for others it's a sort of visual projection, as if they were visualizing rhythmic movements or some conductor, and still others can hear internally something like a metronome tick.
And to make things worse, there isn't a well established, reliable way of teaching that, and as a result, bar a few tips, most musicians are more or less left to figure it out for themselves.
I have actually spent quite some time studying this very issue, with a view to possibly designing a training system for this kind of skill, and could talk a lot more about it, but in order to be as useful as possible to you in the shortest time possible I'll give you two points to consider, hoping you can get something useful from them.
1
Realize that you can only pay attention to music in one way at a time. There are many ways to pay attention to music (follow the rhythm, follow the melody, follow the harmony, follow the mechanics of play, etc.) but you can only do one at a time, and whenever you switch your focus to one (e.g. the mechanics of playing a trill) inevitably you lose most of you conscious attention to anything else.
In your specific case this means that you have essentially two main ways of achieving your goal:
A) Keep your attention on the trill, after having internalized the beat to such a strong degree that you don't lose it if even if you don't pay attention to it. Essentially, this is as if you had a metronome ticking vividly in your head, and even if you don't pay attention to it consciously, you can rely on its presence implicitly.
B) Keep your attention on the beat, counting the beat inside, and perform the trill with indirect attention. This requires that your have practiced the mechanics of the trill enough that you can do it with only a fraction of your total attention.
Borrowing a concept from the mechanics of vision, where we have focused vision and peripheral vision, the two alternatives above correspond to putting one aspect at the center of the vision (either the mechanics of playing or the keeping of the beat), and managing the other aspect with the peripheral vision, so to speak.
Both approaches are possible and both can work well with some practice. Which one works best depends on the individual and the specific situation.
2
To improve your ability in mode A above (i.e. focus on the playing and feel the beat with your peripheral awareness) I find that the following exercise can give good results.
The exercise consists in listening to the music you need to play on (in this case it would be just the piano) and keep time by hitting a surface with a stick, pen, drumstick, or something like that. You want to reach the point where you can keep the time effortlessly and very precisely, without using your full attention. In other words, after enough practice, you could be looking around the room, petting your cat, sipping a drink, and your hand should be effortlessly keeping the beat with very good precision.
Obviously, pay as much attention as you need, especially in the beginning, but the goal of the exercise is to eventually be able do keep precise time with little or no direct attention. (And it's important that your movement produces a sharp tick, which you can clearly hear as being either precise or not. Waving a finger in the air or tapping a foot is not sharp enough.)
Once you reach that point, when you will again play your instrument over that accompaniment, you will find that you will have a much stronger sense of the beat running internally. It may feel like a ticking sound, or it may feel like a kinetic pulse of some kind, or some other way -- there's no single best and right way -- but you will definitely feel the beat much more vividly than before.
Hopefully this will help you solve this particular challenge to a satisfactory degree, but in any case I think that it will also be quite helpful in playing in general, and in rhythmically difficult situations in particular.