Accurate and robust simultaneous localization and mapping (SLAM) is essential for autonomous exploration, unmanned transportation, and emergency rescue operations in complex underground spaces. However, the demanding conditions of underground spaces, characterized by poor lighting, weak textures, and high dust levels, pose substantial challenges to SLAM. To address this issue, we propose a graph-based adaptive weighted fusion SLAM (AWF-SLAM) for autonomous robots to achieve accurate and robust SLAM in complex underground spaces. First, a contrast limited adaptive histogram equalization (CLAHE) that combined adaptive gamma correction with weighting distribution (AGCWD) in hue, saturation, and value (HSV) space is proposed to enhance the brightness and contrast of visual images in underground spaces. Then, the performance of each sensor is evaluated using a consistency check based on the Mahalanobis distance to select the optimal configuration for specific conditions. Subsequently, we elaborate an adaptive weighting function model, which leverages the residuals from point cloud matching and the inner point rate of image matching. This model fuses data from light detection and ranging (LiDAR), inertial measurement unit (IMU), and cameras dynamically, enhancing the flexibility of the fusion process. Finally, multiple primitive features are adaptively fused within the factor graph optimization, utilizing a sliding window approach. Extensive experiments were conducted to check the performance of AWF-SLAM using a self-designed mobile robot in underground parking lots, excavated subway tunnels, and complex underground coal mine spaces based on reference trajectories and reconstructions provided by state-of-the-art methods. Satisfactorily, the root mean square error (RMSE) of trajectory translation is only 0.17 m, and the mean relative robustness distance between the point cloud maps reconstructed by AWF-SLAM and the reference point cloud map is lower than 0.09 m. These results indicate a substantial improvement in the accuracy and robustness of SLAM in complex underground spaces.