The animation is played very smoothly at 20-24 frames per second (fps) in the viewport.
This means it takes about 1/20 seconds to render one frame. That's a tiny fraction of a second.
When I press F12 to render, It takes 20 seconds to render a single frame. That's x400 increase in the rendering time of a frame!
I reduced the number of rendering samples to be less than the number of the viewport samples and reduces some other things that may affect the rendering speed but it still takes about 5 seconds to render a single frame. For me, This is still too much given that my PC was able to play the animation in real-time.