Cloud and fog computing architectures are essential for decentralizing computational tasks, enabling efficient processing across user demands and extensive IoT networks. As computational loads grow in complexity and scale, effective task scheduling across these architectures becomes critical for optimizing resource usage and reducing latency. This paper introduces the Marine Predators Algorithm (MPA), a novel nature-inspired optimization approach to address the task scheduling challenge within cloud and fog environments. Due to the complexity and high-dimensionality of the scheduling problem, MPA was tested on both synthetic and real-world workloads, including HPC2N, NASA iPSC, and GOCJ datasets. Simulation results indicate that MPA outperforms several existing algorithms, achieving significant reductions in average makespan times and enhancing the Degree of Imbalancing, thereby ensuring more efficient resource distribution. These findings underscore MPA’s effectiveness in addressing the demanding task scheduling requirements of decentralized computing environments, positioning it as a promising solution for improved performance and resource utilization in cloud and fog infrastructures.