Heart disease is one of the most prevalent and critical diseases that endangers the lives of human beings. In addition to clinical diagnosis, machine learning and deep learning-based approaches are vital in the diagnosis of heart disease. This paper proposes a balanced and optimized machine-learning algorithm for heart disease detection. This technique combines oversampling techniques, attribute pruning, CART decision tree classifier, and rule pruning through hyper-parameter tuning to identify the presence of heart disease. It further identifies the key attributes that contribute to the occurrence of heart malfunctioning. Experimental results show that SMOTE sampled dataset exhibits effective performance when implemented using a balanced and optimized machine learning algorithm, with an improvement of 11%, 75%, 62%, and 71% in accuracy, precision, recall, and f1 scores when compared with the dataset that was not subjected to sampling. The algorithm works effectively when the imbalance ratio is high for a dataset. The algorithm can be used to predict the presence of heart disease even in highly imbalanced datasets and identify critical features in the malfunctioning of the heart.