Troicki came in for the higher-ranked Janko Tipsarevic with the tie level at 2-2 and played superbly to defeat Llodra 6-2 6-2 6-3 in Belgrade.
World number three Novak Djokovic had earlier brought Serbia level with a 6-2 6-2 6-4 win over Gael Monfils.
Serbia are the 13th nation to win the Davis Cup since its inception in 1900.
“My players showed that they are mentally the strongest team in the world,” said Serbia captain Bogdan Obradovic. “We showed we are number one.”
And France captain Guy Forget admitted: “We had expected two difficult matches today, but what we didn’t expect was that Viktor would be so good.”
Serbia only made their Davis Cup debut in 1995 and both Djokovic and Obradovic had said before the final that victory would be the greatest achievement in the nation’s short sporting history.
Serbia went into the final day trailing 2-1 after Llodra and Arnaud Clement had fought back from two sets down to claim a stunning win over Troicki and Nenad Zimonjic in Saturday’s doubles rubber.
Djokovic played superbly in front of a fervent crowd of over 16,000 at the Belgrade Arena as he swept past Monfils in Sunday’s opening singles to level the tie.
He stormed through the first two sets and looked to be cruising to his sixth straight win over the Frenchman, but had to survive a pulsating third set before clinching victory.
The world number three twice fell a break behind, smashing his racquet in absolute fury on the second occasion, but hit back immediately both times before closing out the match.
“Under the circumstances, with huge pressure, I played an amazing match,” said Djokovic. “Everything was working.”
And he then delivered a message to his home crowd in Serbian, before explaining: “My message was for them to stay. I know it’s difficult in a best-of-five match, it can last hours and hours, but the next match is the most important in maybe all our careers.”
Both captains opted to change their choice of number two singles player for the decisive rubber, with Llodra coming in for Gilles Simon and, perhaps more surprisingly, Troicki taking over from the higher-ranked but out-of-form Tipsarevic.
The chosen pair had never met before and the 30-year-old Llodra certainly had the edge in terms of experience, but it was Troicki, 24, who settled much the better in what was by far the biggest match of either man’s career.
He broke twice as he dominated the first set and snuffed out any sense of a Llodra revival by reeling off eight straight games from 2-0 down in the second to assume complete control.
A double-fault from Llodra on break point at the start of the third suggested his challenge was all but over and that was confirmed when the Frenchman did exactly the same four games later.
Troicki handed back one of the breaks at 4-2 but sealed a historic victory with a blistering backhand return after two hours and 12 minutes before being mobbed by his joyous team-mates as they sprinted across the court to congratulate him.
“This is the most unbelievable moment of my life,” Troicki said afterwards.
And Djokovic added: “It’s historic. This is our biggest success as individuals, as a team, as a country. We are not even aware of what we have done.
“This is the best moment of my career and probably of my nation. This is like winning the World Cup for us.”