Agriculture drives Somalia's economy, but challenges like unpredictable weather, limited resources, and poor infrastructure hamper productivity and economic progress. Emerging technologies like machine learning and IoT offer transformative solutions, optimizing crop yield and resource use. This research demonstrates the substantial impact of integrating Machine Learning (ML) and Internet of Things (IoT) technologies to improve agricultural decisions in Somalia. The study conducts a comprehensive comparison of Decision Trees (DT), K-nearest Neighbor (KNN), and Random Forest algorithms within a Crop Recommendation System. The Decision Tree algorithm emerges as the standout performer, boasting an impressive accuracy of 99.2% and achieving well-balanced precision, recall, and F1-score metrics. Its transparency and interpretability render it an optimal choice for guiding agricultural choices. Despite slightly trailing in performance, KNN and Random Forest algorithms achieve accuracies of 97.2% and 99.0% respectively, presenting valuable alternatives for various contexts. The successful implementation of the Crop Recommendation System, particularly in Somalia's Balcad District, underscores the tangible advantages of real-time IoT data and the Decision Tree model. This system enables farmers to optimize crop selection, thereby enhancing sustainability and yield potential. In a broader context, this research underscores the capacity of data-driven agriculture to tackle food security challenges and drive economic advancement. The transparent and accurate attributes of the Decision Tree algorithm, coupled with IoT capabilities, establish a framework for modernizing traditional farming practices and shaping a more productive future for Somalia and the global agriculture. The continuous evolution of crop recommendation systems holds promise for further transformative opportunities within the agricultural sector.