In the context of tropical mathematics, the problem of solving a vector equation with two given matrices and unknown vectors, each part of which has the form of a product of one of the matrices and an unknown vector, is considered. Such an equation, which has an unknown vector on either side of the equal sign, is often called a two-sided equation. A new procedure for solving two-sided equations is proposed based on minimizing some distance function between the vectors of tropical vector spaces that are generated by the columns of each of the matrices. As a result of the procedure, a pair of vectors is obtained, which provides a minimum distance between the spaces and the value of the distance itself. If the equation has solutions, then the resulting vectors are the solution to the equation. Otherwise, these vectors define a pseudo-solution that minimizes the deviation of one side of the equation from the other. Execution of the procedure consists in constructing a sequence of vectors that are pseudo-solutions of the two-sided equation in which the left and right sides are alternately replaced by constant vectors. Unlike the well-known alternating algorithm, in which the corresponding inequalities are solved one by one instead of equations, the proposed procedure uses a different argument, looks simpler, and allows one to establish natural criteria for completing calculations. If the equation has no solutions, the procedure also finds a pseudo-solution and determines the value of the error associated with it, which can be useful in solving approximation problems.