First thing you really need to do is drain all that water logged crud outta there and clean everything up and do the same with the transmission and rear differential. Amazing what mechanical stuff will withstand...
In as much as I don't own a little Yanmar I'm not sure what broke but, by the looks of the retainer ring, it appears some shadetree mechanic has already visited that spot.
Good luck and NEVER RUN IN 4WD UNLESS THE FRONT END LOOSES TRACTION,,,,,,,,,,,,,NEVER. Not only is it extremely hard on the driveline, it eats tires up right away. The guy at the stealership (not misspelled), out to be hung up by his balls. he's an idiot for telling you that.
It only rakes a tiny sliver of metal in the gears to lock the gears up.