Help with Gyms

Please help me understand LOL.
A level 3 Red Gym has three peoples Pok?mon's assigned to it. Correct? I'm team yellow. So if I defeat all three of them, why can't I take it over? I'm missing something.
What I see after I defeat everyone is the gym losing power but still a circle displays with some power left in it I guess. Should I continue to fight or how does that work?
Edit:
I went to a gym defeated everyone, juiced up my guys and thought again in the gym level dropped.
I kept fighting thru level 1 and took over the gym.
I do not play Pok?mon Go, but hopefully members that do will reply soon with an answer for you...🙂
Wish I knew. Lol. I am not a good fighter.
Yes, you must take the prestige points of the gym down to zero to take it over.
Beating 3 Pokemon in a level 3 gym (not your team) will reduce the gym to level 2 or 1 with a corresponding number of Pokemon guarding it. Once you bring it down to zero, or neutral, you will be able to claim the gym for your team and place a Pokemon inside

Original thread: https://forums.imore.com/threads/help-with-gyms.369065/