Although screening and early diagnosis is critical for preventing irreversible progression of pulmonary hypertension (PH) and preventable mortality, there are no suitable tools for this purpose. We developed and validated an artificial intelligence (AI) algorithm for predicting PH using electrocardiography (ECG). This retrospective cohort study included data from two hospitals. An AI algorithm was developed using 56,670 ECGs from 24,202 patients. Internal validation of the algorithm was performed with 3174 patients from one hospital, while external validation was performed with 10,865 patients from another hospital. The endpoint was the diagnosis of PH, confirmed by echocardiography. We used demographic information, features, and 500-Hz ECG raw data as predictive variables. Additionally, we identified which region had the most significant effect on the decision-making of the AI algorithm using a sensitivity map. During the internal and external validation, the area under the receiver operating characteristic curve of the AI algorithm using a 12-lead ECG for detecting PH was 0.859 and 0.902, respectively, while that using a single-lead ECG was 0.824 and 0.832, respectively. In the 2939 non-PH individuals at initial echocardiography, those patients that the AI defined as high risk had a significantly higher chance of development of PH than the low risk group (31.5% vs. 5.9%, p <0.001) during the follow-up period. The sensitivity map showed the AI algorithm focused on the S-wave, P-wave, and T-wave for each patient by QRS complex characteristics. The AI algorithm demonstrated high accuracy for PH prediction using 12-lead and single-lead ECGs.