Marc Rebes scored the only goal in the 26th minute with a looping header which caught Hungary goalkeeper Peter Gulacsi off guard and went in off the far post.
For Hungary, it was one of their most embarrassing results and effectively ended their hopes of reaching next year's World Cup finals in Russia. They are third in Group B but eight points behind second-placed Portugal, with each team having four games left to play.
Andorra's win was far from pretty as they had only 30 percent of possession and committed 23 fouls to Hungary's 20 in a stop-start match.
Andorra's previous, and only other, win in a competitive match was a 1-0 victory over Macedonia in a World Cup qualifier in October 2004.
However, they have shown signs of improvement, beating San Marino 2-0 in a friendly in February and holding Faroe Islands 0-0 in a World Cup qualifier in March. Remarkably, they have now kept three successive clean sheets.
(Writing by Brian Homewood in Berne, editing by Pritha Sarkar)