The application provides a rotating mechanism and a foldable electronic device. The rotating mechanism comprises a connecting piece, a first swing arm, a stop sliding piece and a stop elastic piece. The first swing arm comprises a guide sliding rod. The guide sliding rod, the stop sliding piece and the stop elastic piece are arranged on the connecting piece. In a first direction, the guide sliding rod, the stop sliding piece and the stop elastic piece are arranged in sequence. The stop sliding piece is provided with a stop concave-convex end. The stop elastic piece extrudes the stop sliding piece, so that the stop concave-convex end can abut against the guide sliding rod. The stop concave-convex end comprises a first convex part, a stop concave part and a second convex part. In a second direction, the first convex part, the stop concave part and the second convex part are connected in sequence. The guide sliding rod can move in the second direction to abut against the first convex part, the stop concave part or the second convex part. When the guide sliding rod abuts against the stop concave part, the first swing arm is stationary relative to the connecting piece, so that the rotating mechanism is in a first state. The guide sliding rod and the stop concave part have a simple cooperation structure, and the rotating mechanism can maintain a stable first state.