In this study, we aimed to investigate disparities in the tumor immune microenvironment (TME) between primary and metastatic malignant melanoma (MM) using single-cell RNA sequencing (scRNA-seq) and to identify metastasis-related T cell marker genes (MRTMGs) for predicting patient survival using machine learning techniques. We identified 6 distinct T cell clusters in 10×scRNA-seq data utilizing the Uniform Manifold Approximation and Projection (UMAP) algorithm. Four machine learning algorithms highlighted SRGN, PMEL, GPR143, EIF4A2, and DSP as pivotal MRTMGs, forming the foundation of the MRTMGs signature. A high MRTMGs signature was found to be correlated with poorer overall survival (OS) and suppression of antitumor immunity in MM patients. We developed a nomogram that combines the MRTMGs signature with the T stage and N stage, which accurately predicts 1-year, 3-year, and 5-year OS probabilities. Furthermore, in an immunotherapy cohort, a high MRTMG signature was associated with an unfavorable response to anti-programmed death 1 (PD-1) therapy. In conclusion, primary and metastatic MM display distinct TME landscapes with different T cell subsets playing crucial roles in metastasis. The MRTMGs signature, established through machine learning, holds potential as a valuable biomarker for predicting the survival of MM patients and their response to anti-PD-1 therapy.