Myocardial infarction (MI), usually termed as heart attack, is one of the main cardiovascular diseases that occur due to the blockage of coronary arteries. This blockage reduces the blood supply to heart muscles, and a prolonged deficiency of blood supply causes the death of heart muscles leading to a heart attack that may cause death. An electrocardiogram (ECG) is used to diagnose MI as it causes variations like ST-T changes in the recorded ECG. Manual inspection of these variations is a tedious task and also requires expertise as the variations produced by MI are often very short in duration with a low amplitude. Hence, these changes may be misinterpreted, leading to delayed diagnosis and appropriate treatment. Therefore, computer-aided analysis of ECG may help to detect MI automatically. In this study, a robust deep learning model is proposed to detect MI based on heart rate variability (HRV) analysis of ECG signals from a single lead. Ultrashort-term HRV analysis is performed to compute HRV analysis features from time-domain and frequency-domain parameters through power spectral density estimations. Nonlinear HRV parameters are also computed using Poincare Plot, Recurrence Analysis, and Detrended Fluctuation Analysis. A finely tuned customized artificial neural network (ANN) algorithm is applied on 23 HRV features for MI detection and classification. The K-fold validation method is used to avoid any biases in results and reported 99.1% accuracy, 100% sensitivity, 98.1% specificity, and 99.0% F1 for MI detection, whereas 98.85% accuracy, 97.40% sensitivity, 99.05% specificity, and 97.70% F1 score is achieved for classification. Furthermore, the ANN algorithm completed its execution in just 59 seconds that indicates the efficiency of the proposed ANN model. The overall performance in terms of computed evaluation matrices and execution time indicates the robustness and cost-effectiveness of the proposed methodology. Thus, the proposed model can be used for high-performance MI detection, even in wearable devices.