The new COVID-19 is rapidly spreading and has already claimed the lives of numerous people. The virus is highly destructive to the human lungs, and early detection is critical. As a result, this paper presents a hybrid approach based on deep convolutional neural networks that are very effective tools for image classification. The feature vectors were extracted from the images using a deep convolutional neural network, and the binary differential metaheuristic algorithm was used to select the most valuable features. The SVM classifier was then given these optimized features. For the study, a database containing images from three categories, including COVID-19, pneumonia, and a healthy category, included 1092 X-ray samples, was used. The proposed method achieved a 99.43% accuracy, a 99.16% sensitivity, and a 99.57% specificity. Our findings indicate that the proposed method outperformed recent studies on COVID-19 detection using X-ray images.