My opinion... technically legal on his part, but tool move for sure. Time of check in is whoever is first line at the counter, at the right gate, when the right agent shows up. So he beat you on a technicality.
But reasonable etiquette is if someone is clearly at the gate before you, you should defer to them. Not always possible, if somebody was sitting in the back in civvies, but in that case he should have been hovering near the counter waiting for the agent to show.
I would have called him out. If it came down to it, I would have asked to speak to the CA.