I assume that prior to dropping the mainsail that you had gotten the boat lying on it's side (mast now floating instead of stuck down in the mud in a 'semi-turtle' position). I've sometimes gone to the end of the mast and swum the end around until the boat is pointing into the wind. After a capsize, I usually get to the end of the mast quickly to try and avoid a turtle if it's not already to late. I then swim the boat around so that the wind is blowing at 45 degrees to the bows (into the V shaped by the bows and the mast). A small direction correction might need to be made once you get on the waterborn hull. I think it's amazing that you were able to right that boat solo and without the sail! A major reason for pointing the bows into the wind is so the sail can catch the wind and fly like an airplane wing. Cool.
The reason the boat took off downwind is because your main sail was down. Even pointed into the wind, sailing with the jib only will turn the nose down and run downwind.