Long, long ago I had a sail boat and from those days I remember now that she would yaw terribly, about 40° while at anchor in a moderate wind.
An anchored boat is an unstable system, mainly because of its topsides that act as a (bad) foresail. Actually, the wind tends to put the boat broadside to the wind, whereas the rode tension tends to bring it back into the wind.
Initially, the boat is stationary, with its rode parallel to the wind, but its bow is headed slightly off the wind (yaw = 1 degree). The windage asymmetry due to this small yaw angle creates a torque that tends to increase this angle, plus a lateral force that pushes the boat abeam. Since the boat is tied to the seabed by the rode, this lateral force results in a near circular motion around the anchor (swing).
At one moment, the various forces balance each other, so the yaw angle rate changes sign. This slows down the swing angle rate, which eventually changes sign in its turn: the boat swings back on the opposite tack.
Now that the pendulum-like motion is initiated, it will last forever!
For a yacht there is a rather simple cure. Tie a long line to the anchor rode at the bow. Let out the anchor rode until the hitch is 1 - 2 meters underwater. For the final adjustment tighten this stern line, bringing the stern towards the wind until the boat no longer yaws and tie it off.