I admit, this is secondhand, and I am sketchy on the details, but a friend of mine is dealing with the same thing with one of her sons who is the same age. He is apparently gifted, can read at a 5th grade level, can do math at a 2nd to 3rd grade level, but oftentimes acts like a 2 year old - horrible tantrums, can't take no for an answer, or just cooperate and follow the rules "just because". What they were told is that these kids often may be academically and intellectually gifted, but at the same time, are often socially and maturity-wise way behind. They also expect that a lot of it with him is him being bored, since he hasn't even started kindergarten yet and he is way more advanced than the pre-K curriculum he is expected to follow now. And he gets frustrated easily, with less ability to cope with it.
Keep in mind too that all kids act bratty at times - no child is a perfect angel 100% of the time. If you don't see other kids acting this way, you are not seeing them 24 hours a day. I've been told by my daughter's preschool teacher that she is the happiest, most well-adjusted child she has ever seen and yet, she has her moments at home (and elsewhere) where she is having a melt-down and acts like she is losing her mind. She is very strong-willed for sure (as is my friend's son) and life is definitely a challenge at times (she turns 5 in August and will be starting kindergarten and I have no idea if she is "gifted" or not - I do know she is very bright, but no matter what, she doesn't get a "free pass" on her behavior).
Maybe if you could find some kind of support group, that might help. But I also think that just because he is gifted, and may have a reason behind the way he acts, that doesn't make it acceptable. He still needs to be disciplined for the whining, etc. My friend and I have utilized both time-outs, and taking things away, for unacceptable behavior. I would also consult with a behaviorist who has experience dealing with kids like this, who can hopefully help you with the more challenging, day-to-day stuff. He might also have other things going on, like ADHD, possibly, or issues with impulse control. I wish you luck.