Fog Computing (FC) is an emerging paradigm that extends cloud computing toward the edge of the network. In particular, FC refers to a distributed computing infrastructure confined on a limited geographical area within which some Internet of Things applications/services run directly at the network edge on smart devices having computing, storage, and network connectivity, named fog nodes (FNs), with the goal of improving efficiency and reducing the amount of data that needs to be sent to the Cloud for massive data processing, analysis, and storage. This paper proposes an efficient strategy to offload computationally intensive tasks from end-user devices to FNs. The computation offload problem is formulated here as a matching game with externalities, with the aim of minimizing the worst case service time by taking into account both computational and communications costs. In particular, this paper proposes a strategy based on the deferred acceptance algorithm to achieve the efficient allocation in a distributed mode and ensuring stability over the matching outcome. The performance of the proposed method is evaluated by resorting to computer simulations in terms of worst total completion time, mean waiting, and mean total completion time per task. Moreover, with the aim of highlighting the advantages of the proposed method, performance comparisons with different alternatives are also presented and critically discussed. Finally, a fairness analysis of the proposed allocation strategy is also provided on the basis of the evaluation of the Jain's index.