Make sure you are motivated by the ultimate mission of whatever you’re working on, and you understand the connection from that all the way down to the specific work you’re doing at any given moment.
Focus on getting better at whatever it is you’re doing. There is a reason why the most addictive RPGs formalize the “leveling up” dynamic and it’s amazing how much tedious work this can motivate. Enjoy the day-to-day work itself. Don’t expect to enjoy everything, but it can really help your motivation to have a job where you enjoy a significant part of the work intrinsically.
Take care of yourself. Make sure you look out for your psychological needs and get enough rest, take time to relax with friends, get exercise or whatever else you need to be able to focus on work without the rest of your life dragging you down.
Have an internal sense of what’s worthwhile and don’t fool yourself. Some people think of “staying focused” as an issue of psychological willpower. In my experience one of the biggest reasons people don’t focus is that they don’t have a strong sense of the value of all the different things they could do. They will get lured in by things that seem exciting or things that will get them some kind of short term social status but have little to do with what actually matters in the long term. It is much easier to avoid this stuff if you have a good sense of its value.
I used to make internet products for fun before it became my work, so I’m lucky to be in a position where I intrinsically enjoy large parts of the work I have to do every day. For the other parts, I am more motivated by our mission and the impact I expect the work to have on the world, and by getting better.
Also, as a leader, the things you do well and do badly get magnified throughout the team you are leading. You can see entire companies get thrashed around when the CEO can’t focus, or move slowly when the leader isn’t motivated. I am deeply aware of these effects and so the responsibility I have and the people depending on me end up giving me a lot of motivation to focus, work hard, and make good decisions.