Background: Melanoma is a highly aggressive form of skin cancer, necessitating early and accurate detection for effective treatment. This study aims to develop a novel classification system for melanoma detection that integrates Convolutional Neural Networks (CNNs) for feature extraction and the Aquila Optimizer (AO) for feature dimension reduction, improving both computational efficiency and classification accuracy. Methods: The proposed method utilized CNNs to extract features from melanoma images, while the AO was employed to reduce feature dimensionality, enhancing the performance of the model. The effectiveness of this hybrid approach was evaluated on three publicly available datasets: ISIC 2019, ISBI 2016, and ISBI 2017. Results: For the ISIC 2019 dataset, the model achieved 97.46% sensitivity, 98.89% specificity, 98.42% accuracy, 97.91% precision, 97.68% F1-score, and 99.12% AUC-ROC. On the ISBI 2016 dataset, it reached 98.45% sensitivity, 98.24% specificity, 97.22% accuracy, 97.84% precision, 97.62% F1-score, and 98.97% AUC-ROC. For ISBI 2017, the results were 98.44% sensitivity, 98.86% specificity, 97.96% accuracy, 98.12% precision, 97.88% F1-score, and 99.03% AUC-ROC. The proposed method outperforms existing advanced techniques, with a 4.2% higher accuracy, a 6.2% improvement in sensitivity, and a 5.8% increase in specificity. Additionally, the AO reduced computational complexity by up to 37.5%. Conclusions: The deep learning-Aquila Optimizer (DL-AO) framework offers a highly efficient and accurate approach for melanoma detection, making it suitable for deployment in resource-constrained environments such as mobile and edge computing platforms. The integration of DL with metaheuristic optimization significantly enhances accuracy, robustness, and computational efficiency in melanoma detection.