First suggestion: make sure the meeting has an agenda in the first place. If the meeting invitation doesn't specify one, you can ask the sender to clarify it.
The second suggestion is to say something when the meeting has gone off track. This one is a little more challenging because it depends on a number of factors, including the relative seniority of the participants, general cultural norms at your workplace, your own comfort confronting somebody who's veered, etc.
I'll call "time check" when the participants are either above me, or more than a level or so below me, just because it's helpful to be sensitive in such contexts.
If the participants are my peers or pretty close to it, then I'll generally say things like "we don't have to design it here", "let's take that offline", "we need to cover the rest of the agenda", etc., interrupting if I have to.
These strategies have worked pretty well for me.