The best way to avoid tilt is to understand why things happen. This involves a proper comprehension of the maths behind poker, both the specifics (what percentage of the time with a gutshot hit on the turn, say) and the fundamentals (how probability works, the relative value of tournament chips, managing expectations, why bankroll management works, etc.).

If you understand all these things, then not only can you use them to play more correct poker, but you can also understand and rationalise when things AREN'T going your way.