Victory is granted to the side retaining the field after the battle. so, if one side is forced into retreat through failing morale, the other side wins.
Since the battle is in a marsh region, force composition may have played a large role here. Difficult terrain limits frontage greatly. If the defender has a lot of small artillery (6lber) a lot more of them will get into frontage than if the attacker has mostly larger artillery (12lber).
Simple luck does play some role too. Generally not so much, but sometimes.