Photovoltaic (PV) generation systems that are partially shaded have a non-linear operating curve that is highly dependent on temperature and irradiance conditions. Shading from surrounding objects like clouds, trees, and buildings creates partial shading conditions (PSC) that can cause hot spot formation on PV panels. To prevent this, bypass diodes are installed in parallel across each panel, resulting in a global maximum power point (GMPP) and multiple local maximum power points (LMPPs) on the power-voltage (P-V) curve. Traditional methods for maximum power point tracking (MPPT), such as perturb and observe (P&O) and incremental conductance (INC), converge for LMPPs on the P-V curve, but metaheuristic algorithms can track the GMPP effectively. This paper proposes a new, efficient, and robust GMPP tracking technique based on a nature-inspired algorithm called Ali Baba and the Forty Thieves (AFT). Utilizing the AFT algorithm for MPPT in PV systems has several novel features and advantages, including its adaptability, exploration-exploitation balance, simplicity, efficiency, and innovative approach. These characteristics make AFT a promising choice for enhancing the efficiency of PV systems under varied circumstances. The performance of the proposed method in tracking the GMPP is evaluated using a simulation model under MATLAB/Simulink environment, the achieved simulation results are compared to particle swarm optimization (PSO). The proposed method is also tested in real-time using the Hardware-in-the-loop (HIL) emulator to validate the achieved simulation results. The findings indicate that the proposed AFT-based GMPP tracking method performs better under complex partial irradiance conditions than PSO.