Two judges scored the bout 114-114, while the third made Huck a 115-113 winner in front of his home crowd.
Afolabi made all the early running in the bout to take an early lead, but after Huck sustained a bloody nose in the third round he emerged reinvigorated - spurred on by his trainer yelling at him to "do something" while back in his corner.
Huck might have earned a knockout as he had Afolabi reeling in the ninth, and again in the final round when both fighters were clearly shattered.
"I was tired early on, but I'm a fighter and I fought," Huck said. "Thankfully it was just enough in the end."
Afolabi paid tribute to his opponent's determination.
"I give Marco a a lot of credit," Afolabi said. "I thought he was tired around round six, but he just kept coming until round 12."
On the same card WBO super middleweight champion
Stieglitz had been expected to knock out an opponent rated a no-hoper before the bout, though he safely completed a points victory scored 120-108, 117-111, 117-111.
Also in Erfurt
Pulev, who is now undefeated in 16 fights, was well ahead on points before the knockout blow.