This is a pretty common issue at five, and my five year old son is certainly in the same general class of student as yours: very bright, excellent worker, but not always on his best behavior.
The first thing I'd note is that this is some of the most valuable learning he will do in this age level/grade level. The first year or two of school, most bright students don't have to expend much efforts learning; the point of the first year or two of schooling is to bring the students all to the same level more or less (so, for example, my son came into school knowing how to read, add, subtract, multiply; many other students need to learn letters and numbers still). So he probably won't learn much academically, other than filling in the gaps that he didn't have before; even if he came in knowing relatively little, he probably will pick up quickly what's taught and have a lot of brain time free.
What he should be learning mostly is socialization and how to behave in groups/in public/in school. Socialization aside as that's probably obvious, by nine or ten it's going to be very important that he knows how to sit quietly and listen even when he's bored. He needs to work out how to deal with the school environment, on his own terms but also on theirs.
The first thing you can do is make sure he's set up for success. Make sure he sleeps enough and eats enough in the morning. More protein less sugar when possible. Each kid is different sleep-wise, but he should be getting sufficient sleep preferably such that he wakes up himself; this is our biggest problem as my son doesn't really sleep well and won't go to sleep early enough to be able to get enough sleep. But on days when he does, he has far better days in school. Do what you can to make sure his body is set up to be able to succeed, first off.
Second, consistency can be helpful. One thing that was super helpful for my son was setting up things at home mirroring school: behavior chart, reward chart, even "day of the week" and letter/number charts on the walls. This helped him feel comfortable at home and at school, and improved his willingness to fit into the school's systems. Talk to your teacher, ask them how they handle behavior. Maybe they have a chart where the child moves up/down based on behavior (mine does). Maybe they have some other system, stars for good behavior, things like that. See if you can implement something similar at home.
Third, talk to your son about how his day went every day. Don't approach it as a discipline situation: approach it as a learning situation. He should feel comfortable telling you he had a bad day, and not expect discipline; instead, you should talk to him about the reasons for it, and help him learn how to identify those reasons. If he had a bad day, ask if he was tired. Ask if he was hungry. Ask if he was distracted. Go through the different things that can cause misbehavior. Helping him figure out why he's having trouble behaving will help him learn how to behave!
Fourth, be positive. Find the positives wherever you can. Even if he has 4 bad days in a week, if he has one good day, accentuate that. Talk to him about it. Celebrate it. Start with that baseline, and then say "Okay, one good day this week. Sounds great. What can we do to get to two good days next week?". Negativity reinforces negative behaviors, while positivity reinforces positive behaviors. It's important your son believe he can behave well. Boys in particular at that age often are trained by the school system to believe they cannot.
Fifth, work with the schools to do all of the above. Talk to them about how they handle your son's misbehavior, and see if maybe they can adjust their actions to help him succeed. If the teacher is always negative, your son won't feel good about himself and his chances of success. She/he needs to be positive sometimes. They may need to adjust their baseline, in order for him to feel like he can succeed. Your son is also not the first child they've had like this, nor is he the worst - I guarantee it. They may have suggestions for how to help at home, but don't let that keep you from pushing them to do a better job on their side.
Sixth, help your son learn how to handle boredness. He's obviously bright, and with that comes some tendency towards boredness. I hated it in school when I already understood things the teacher was explaining five or ten minutes longer than I needed to. Things that can be super helpful:
- Fiddle devices. Things that you can hold in one hand and manipulate in some fashion - think someone twiddling a pen between their fingers, but with something that you can actually move. I used to play with erasers for example, or even just open/close a retractable pen.
- Teach him how to find more complex ways to solve the problems the teacher is presenting. If the teacher is teaching some letters or words, teach him to think of similar words, or to think of sentences with that word. If they're teaching addition, think of adding more complicated numbers. Not something that will distract him to the point of not learning, but something similar to what the teacher is doing but harder. This will help him in the long run.
- Assuming the teacher is okay with this, tell him to write down things he wants to tell his friend when they come to his mind, in a notebook or something, rather than tell it right away. Five year olds urgently have to tell everyone everything that comes to mind right away. If he can write it down, maybe that will help him feel better that he won't forget later.
Finally, remember that he won't instantly get better, and this is a multi-year process. Celebrate the small gains, and don't expect him to suddenly be a perfect angel in school. It's like cleaning a messy room; you don't just snap your fingers and clean it, you have to pick up one thing and then the next.