I enabled Ambient Occlusion in the render settings and it's enabled in the viewport, as shown in this screenshot:
However, in the render output, it has no ambient occlusion:
What am I doing wrong?
Well, the problem is that you enable not an AO, but SSAO, and SS (stands for screen space) make a huge difference in your particular case. So what does SS mean? That means the AO effect limited to the zone that you have in frame. So if something is outside the frame, SS-effect doesn't know about it (Same for SSSSS, SS-reflection, SS-refraction as well) So this is a limitation of the algorithm.
So how you can fix that? Well in your case is easy. Just enable Overscan option in render settings:
This option increase render field in all directions, so borders will be rendered, SSAO will be applied more accurate, and then trimmed by actual render frame.