Fog computing is considered a derivative of cloud computing that aims to reduce the huge transmission latency and CPU time, as well as the overall cost of resource usage in the cloud. The deployment of Internet-of-Things (IoT) enabled smart systems, which frequently demand real-time processing, is rapidly expanding. Following that, the volume of generated data and computation workload dramatically increased. Fog resources are limited and typically resource constrained. Therefore, it is impossible to execute all tasks at the edge network. To support the increasing amounts of data and computation, cloud computing, associated with significant delays in transmission and processing of workload, is used. The distribution of tasks between the cloud and fog layer and the allocation of layer resources to satisfy the users' demands prevents layer oversaturation, service degradation, and resource failure due to excessive workload is challenging. This paper proposes a layer fit algorithm that evenly distributes tasks between the fog and cloud, based on priority levels. Also, a Modified Harris-Hawks Optimization (MHHO) based meta-heuristic approach is proposed to assign the best available resource to a task within a layer. The key intention of this paper is to reduce the makespan time, task execution cost, and power consumption and enhance resource usage in both the fog and cloud layer. The simulations are performed using the iFogSim simulation toolkit. The proposed layer fit algorithm and the Modified Harris-Hawks Optimization (MHHO) are compared with the traditional Harris-Hawks Optimization (HHO), Ant Colony Optimization (ACO), Particle Swarm Optimization (PSO), and the Firefly Algorithm (FA). Based on the experimental results, the MHHO has improved the performance of the system in terms of makespan time, execution cost, and energy consumption. The ability of the MHHO to balance the load across resources yields a significant improvement when the number of tasks increases as compared to the traditional HHO and other optimization algorithms. © 2023, The Author(s), under exclusive licence to Springer-Verlag GmbH Germany, part of Springer Nature.