The Swiss, playing his first match in two months, won the first set but succumbed to the German in the second-set tie-break having had match point.
"It's always special to play a close friend like Roger on grass, always lots of emotion," said the world 302.
"I saved a match point so was able to play more freely after that."
He added: "I even shocked myself."
It was Haas' fourth victory in 17 meetings against the former world number one.
The 35-year-old, who has started his build-up to Wimbledon, had not played since winning the Miami Open against Rafael Nadal in April and missed the entire clay court season.
It was only the world number five's second defeat of the 2017 season.
Seven-time Wimbledon champion Roger Federer was beaten 2-6 7-6 (10-8) 6-4 by 39-year-old Tommy Haas on grass at the Stuttgart Open.