The company already sponsors the William Hill Scottish Cup and is the official betting partner of the Scottish Premier League.
"It's really exciting to be involved with the Scottish national team," said William Hill chief marketing officer Kristof Fahy. "The road to Rio is going to be fascinating - and we're hoping to support the Scottish national team all the way to a place in the World Cup finals in 2014."
Campbell Ogilvie, president of the Scottish FA, said William Hill had now cemented its places as one of the biggest supporters of Scottish football.
The deal, which comes into immediate effect, will see William Hill benefit from a wide range of sponsorship rights, including advertising, branding, hospitality and exclusive Scotland imagery and content.