Before you read this, be sure that you understand how the horse and wagon works without friction.
Compared to the previous diagram, you can see that two new forces have been added to the diagram at the right. The friction force acting on the wagon (colored red) tries to oppose the motion of the wagon. It is exerted by the ground. Its Newton's Third Law force partner is the force "wagon pushes ground". Note that the force pushing the wagon is drawn on the wagon, and the force pushing the ground is drawn on the ground.
As always, these two forces don't cancel because they act on different objects.
Here is an analysis in table form.
Consulting the diagram, notice that there are now two forces acting on the wagon. The net force on the wagon equals the force the horse exerts minus the friction force the ground exerts. If the horse pulls harder on the wagon than the friction force, there will be a forward-pointing net force, and the wagon will accelerate forward. If the pull of the horse exactly balances the friction force, then the net force on the wagon will be zero, and the wagon will not accelerate. (This is the situation when the horse is pulling the wagon at constant velocity.)
The situation for the horse is the same as in the previous (no friction) situation.
There are now 2 forces acting on the ground - the horse pushes it backwards and the wagon pushes it forward. The net force on the ground equals the force that the horse exerts on the ground minus the force that the ground exerts on it. If the horse pushes harder, there will be a backward net force on the ground. If the wagon pushes harder, there will be a forward net force on the ground. If they push equally, the net force on the ground will be zero. In any case, the acceleration of the ground will not be noticeable, due to the enormous mass of the earth.