The Andes Mountains act as a barrier to moisture from the Atlantic Ocean. As air rises over the mountains, it cools and condenses, releasing precipitation on the windward side. By the time the air reaches the other side (the Atacama Desert), it has lost most of its moisture.
The Humboldt Current is a cold ocean current that flows along the western coast of South America. It brings cold water from the Antarctic, cooling the air above it. As the air cools, it can hold less moisture, leading to fewer clouds and less precipitation.
Finally, the ocean plays a role in the Atacama Desert's dryness through upwelling. Upwelling is the process by which cold, nutrient-rich water from the ocean rises to the surface. As the cold water rises, it cools the air above it, further reducing its ability to hold moisture.