The German-born skier, who has still not been universally accepted in his adoptive country, also won the 30km freestyle and combined pursuit earlier in the Olympics.
However, controversy surrounded his latest success after he failed a pre-race blood test before passing a second test and being allowed to complete.
Muehlegg was among 13 men selected at random to undergo a blood test.
His red blood cell count was above the legal level for the first test but beneath the threshold when a second test was carried out five minutes later.
He was therefore allowed to compete.
In the race itself Muehlegg was in second place until a late burst in the final 10 km saw him cross the finishing line in two hours six minutes and 5.9 seconds.
Russia's Mikhail Ivanov took silver in a time almost 15 seconds slower.
The bronze medal went to Andrus Veerpalu of Estonia who won gold in the 15 km classical earlier in the Games.
Muehlegg's golds are Spain's first since 1972 when Francisco Fernandez Ochoa won the alpine skiing slalom.
"Muehlegg sped up dramatically after the first two laps.
And on the upper loop it was so wet that the track was
almost like water."
Mikhail Ivanov, Russian cross country skier
He started to compete for Spain at the beginning of the 1999-2000 season after a falling out with the German federation, but he still spends most of his time living in Germany.
Ochoa himself branded Muehlegg a "mercenary" following his decision to compete for Spain.
The Spanish media too have questioned his commitment to the country amidst widespread speculation that he may one day return to compete for Germany.
Muehlegg, who insists he feels '100% Spanish', said: "I'm so happy to have won for those guys in Spain.
"It was the most difficult race of my life.
"I was sure the last five kilometres would be the decisive section. I never dreamed when I came to Salt Lake City that I would win three gold medals."
Meanwhile, Ivanov admitted he could not match Muehlegg's strength in the closing stages.
"In the last 3 kilometres the wind started picking up, especially on the top of the hills," Ivanov said.
"It was windy and hard to ski.
"Muehlegg sped up dramatically after the first two laps. And on the upper loop it was so wet that the track was almost like water.
"My skis were prepared perfectly for the first two laps. The last lap when the skis were not doing so well I had to fight with myself to keep up."