The artificial intelligence also misdiagnosed fewer benign moles as malignant melanoma, meaning fewer patients would be forced to endure needless surgery.
Researchers from Germany, the United States and France used a form of artificial intelligence known as a deep learning convolutional neural network (CNN).
This is an artificial neural network inspired by the biological processes at work when nerve cells in the brain are connected to each other and respond to what the eye sees.
The CNN learns from images that it "sees" and teaches itself to improve its performance in a process called machine learning.
Professor Holger Haenssle, the study lead author, from the University of Heidelberg, Germany, said: "The CNN works like the brain of a child. To train it, we showed the CNN more than 100,000 images of malignant and benign skin cancers and moles and indicated the diagnosis for each image."
With each training image, the CNN improved its ability to differentiate between benign and malignant lesions.
"Once the machines had been trained, they were tested against 58 dermatologists from 17 countries across the world.
More than half the specialists had at least five years' experience.
The dermatologists were asked to first make a diagnosis of malignant melanoma or benign mole just from the dermoscopic images, and to decide if surgery was required.
Four weeks later they were given the same tests, this time with clinical information about the patient, including their age, sex and position of the lesion.
When doctors were given simply the images, they accurately detected 86.6 per cent of melanomas, rising to 88.9 per cent when they also had information about the patient.
The artificial intelligence made a correct assessment in 95 per cent of cases based on images alone.
"The CNN missed fewer melanomas, meaning it had a higher sensitivity than the dermatologists," said Prof Haenssle.
"And it misdiagnosed fewer benign moles as malignant melanoma, which means it had a higher specificity.
"This would result in less unnecessary surgery."
The computer was more accurate even when compared with the most experienced doctors, the study, published in the Annals of Oncology, found.
"These findings show that deep learning convolutional neural networks are capable of out-performing dermatologists, including extensively trained experts, in the task of detecting melanomas," Prof Haenssle said.
Researchers said such technology could be used to screen for skin cancer, meaning cases could be diagnosed far earlier.
But they said the technology was likely to be used in conjunction with skilled doctors, rather than replacing them.
Malignant melanoma is the most deadly type of skin cancer.