McLeish led Scotland to a shock victory over France in Paris in 2007, with James McFadden netting the stunning long-range winner

Alex McLeish has agreed to become Scotland manager for the second time - 11 years after leaving the post.

McLeish, 59, will sign a deal until 2020 and is the unanimous choice of the Scottish FA board.

He replaces his former Aberdeen and Scotland team-mate Gordon Strachan, who left in October after the country did not qualify for the World Cup.

The SFA tweeted external-link confirmation on Friday: "It's official. Alex McLeish is the new Scotland National Team Head Coach."

The Scottish FA failed in its attempt to recruit Michael O'Neill, who instead chose to stay with Northern Ireland.

Walter Smith was also linked with the role, but ruled himself out of a return to the job he held for three years before leaving for Rangers in 2007.

McLeish's first games in charge will be against Costa Rica and Hungary next month, followed by further friendly matches in Peru in May and Mexico in June.

His debut competitive games will be the Uefa Nations League encounters against Albania at home on 10 September, then in Israel on 11 October.

Scotland have not reached a major finals since the 1998 World Cup in France and the Scottish FA is currently looking for a new chief executive to replace Stewart Regan.

McLeish, who won 77 caps for his country, told BBC Scotland in December that "the national job is something that would interest me" and that he still has "a lot to give the game".

His appointment will be officially announced on Friday morning.

McLeish succeeded Smith midway through the Euro 2008 qualifying campaign and came within one game of reaching those finals, only to lose to Italy.

However, after winning seven of his 10 games in charge, McLeish left for Birmingham City in January 2008.

Speaking to BBC Scotland in July 2014, he said "wild horses couldn't have dragged me" away had he led to country to the finals in Austria and Switzerland.

"I was getting phone calls during the campaign from lower half Premier League teams and I said absolutely not," he said. "I told my agent I don't want any calls, any conversations about going to England because I believed we were going to qualify. But after the Italy game, the calls continued and it starts to play tricks with your mind.

"The only thing that made me leave was these niggly thoughts that I had to wait eight months for the next competitive game."

Birmingham were relegated in McLeish's first season, but he earned them an immediate return to the English top flight and claimed the 2011 League Cup.

Before that, he managed Motherwell, got Hibernian promoted, and won seven trophies - including two league titles - during a near five-year spell with Rangers.

Since leaving Birmingham in 2011, he has managed Aston Villa, Nottingham Forest, Genk in Belgium and Egyptian club Zamalek.

'I don't think he ever thought he'd get it' - analysis

BBC Scotland's senior football reporter Chris McLaughlin

McLeish has been very keen on taking the job but I'm not overly convinced he ever thought he would get it. However, as other candidates ruled themselves out, his name started to steadily rise to the top.

He's a passionate Scot who has been there and done it and he certainly has the gravitas to command respect in the dressing room.

But questions will be asked of the Scottish FA about progress and the process. Does giving a former Scotland manager another shot at the top job really show the country is moving forward? And just what went wrong in the process that the new man is clearly the second choice at best?

The fans will get behind him, though, and if he leads the nation to the promised land of the Euros in 2020, then the above won't matter.

'A lot of Scotland fans haven't forgiven him' - reaction

Former Scotland international Pat Nevin on BBC Radio 5 live

A lot of Scotland fans haven't quite forgiven him for walking out on the job. His record wasn't bad and we were feeling good about ourselves, so a lot of people were disappointed but he's a good manager.

Trying really hard not to be cynical, Alex is free and available unlike people such as Stevie Clarke [Kilmarnock boss], who you would need to buy out of his contract. But Alex was trusted to do the job last time and he didn't let anyone down.

He immediately gets respect from the players. He's managed in the Premier League, he's managed in Scotland in the top league, and he's been an international manager, so there have been a lot of positives. Others will say 'wait a minute, he's had some failures as well', but tell me a manager who hasn't.