How is thrust of engines on the two sides of an airplane kept exactly equal to prevent yawing?
It isn't. The rudder is used.

Yes, if there is asymmetry in thrust, the plane will yaw. And there is asymmetry in thrust. The engine thrust decreases slightly with wear and the engines are often worn out differently. There are effects like P-factor that shift the thrust axis depending on speed and attitude. And of course an engine may fail.

So thrust asymmetry happens and needs to be compensated. And it is compensated by generating some sideways force with the rudder. Either by pilot pushing the pedal, or by applying trim.

As @mins mentions, there are also effects that can cause asymmetry of drag, e.g. icing, and there are situations where the aircraft intentionally needs to fly somewhat sideways, e.g. cross-wind take-off and landing, so rudder is needed for many other things too. And when it's there, it can compensate thrust asymmetry (often, though, the engine failure dictates the minimum size of the vertical stabilizer and rudder).

Note, that P-factor occurs in single-engine propeller aircraft too, so they also have some thrust asymmetry.