The only way to stop making mistakes is to stop doing math entirely (although that too may be a mistake!).
You can reduce the number of mistakes by practice, adopting good habits, and finding ways of doing things that you tend not to mess up.
An example of a good habit is any time you divide by $x$ (or any other variable expression), you immediately stop what you're doing and split the problem into two problems: one where you add the hypothesis $x \neq 0$ (and thus can divide), and one where you add the hypothesis $x=0$ (and thus can't divide, but can simplify)
An example of different ways of doing things is to factor rather than division. If you have an equation $5x^2 = 3x$, don't divide $x$ out, but instead rewrite it as $5x^2 - 3x=0$ and factor the $x$ out to get $x (5x - 3) = 0$. This works out the same as the good habit above, but some people may be less likely to make a mistake if they do things this way.
But the real trick is to learn how to verify your work, and how to find mistakes after you've made them. This too takes lots of practice, and it takes some thought to try and figure out ways to actually do it.
Just to be clear, one of the least effective ways to verify your work is to look over each step again to see if you agree with it. If you have made a mistake, the error is still in your head, which makes you very unlikely to notice it is a mistake.
One approach I often take is to try and solve a problem in a very different fashion; if I get the same answer by two very different approaches, I'm much less likely to make a mistake. It's important to do things differently, because if a mistake is still fresh in your head, you're likely to repeat it if you redo things the same way.