Background: Deep learning has the potential to improve diagnostic accuracy and efficiency in medical image recognition. In the current study, we developed a deep learning algorithm and assessed its performance in discriminating melanoma from nevus using whole-slide pathological images (WSIs). Methods: The deep learning algorithm was trained and validated using a set of 781 WSIs (86 melanomas, 695 nevi) from PLA General Hospital. The diagnostic performance of the algorithm was tested on an independent test set of 104 WSIs (29 melanomas, 75 nevi) from Tianjin Chang Zheng Hospital. The same test set was also diagnostically classified by 7 expert dermatopathologists. Results: The deep learning algorithm receiver operating characteristic (ROC) curve achieved a sensitivity 100% at the specificity of 94.7% in the classification of melanoma and nevus on the test set. The area under ROC curve was 0.99. Dermatopathologists achieved a mean sensitivity and specificity of 95.1% (95% confidence interval [CI]: 92.0%-98.2%) and 96.0% (95% CI: 94.2%-97.8%), respectively. At the operating point of sensitivity of 95.1%, the algorithm revealed a comparable specificity with 7 dermatopathologists (97.3% vs. 96.0%, P = 0.11). At the operating point of specificity of 96.0%, the algorithm also achieved a comparable sensitivity with 7 dermatopathologists (96.5% vs. 95.1%, P = 0.30). A more transparent and interpretable diagnosis could be generated by highlighting the regions of interest recognized by the algorithm in WSIs. Conclusion: The performance of the deep learning algorithm was on par with that of 7 expert dermatopathologists in interpreting WSIs with melanocytic lesions. By pre-screening the suspicious melanoma regions, it might serve as a supplemental diagnostic tool to improve working efficiency of pathologists.