The hyperarid Namib desert is a coastal desert in southwestern Africa and one of the oldest and driest deserts on the planet. It is characterized by a west/east increasing precipitation gradient and by regular coastal fog events (extending up to 75 km inland) that can also provide soil moisture. In this study, we evaluated the role of this natural aridity and xeric gradient on edaphic microbial community structure and function in the Namib desert. A total of 80 individual soil samples were collected at 10-km intervals along a 190-km transect from the fog-dominated western coastal region to the eastern desert boundary. Seventeen physicochemical parameters were measured for each soil sample. Soil parameters reflected the three a priori defined climatic/xeric zones along the transect (“fog,” “low rain,” and “high rain”). Microbial community structures were characterized by terminal restriction fragment length polymorphism fingerprinting and shotgun metaviromics, and their functional capacities were determined by extracellular enzyme activity assays. Both microbial community structures and activities differed significantly between the three xeric zones. The deep sequencing of surface soil metavirome libraries also showed shifts in viral composition along the xeric transect. While bacterial community assembly was influenced by soil chemistry and stochasticity along the transect, variations in community “function” were apparently tuned by xeric stress.