Publicly backed by Indian captain Virat Kohli, 57-year-old Shastri was always the frontrunner as he got a two-year extension till the 2021 Twenty20 World Cup in India.
He saw off competition from former Indian all-rounder Robin Singh, former team manager Lalchand Rajput, former New Zealand coach Mike Hesson, Australia's Tom Moody and Phil Simmons of West Indies.
Simmons had backed out of the interview at the last minute due to personal reasons.
The remaining candidates were interviewed by a three-member cricket advisory committee panel which included World Cup-winning captain Kapil Dev, ex-national coach Anshuman Gaekwad and ex-women's team captain Shantha Rangaswamy.
Dev announced the decision at a Friday press conference.
"Number three was Tom Moody, number two was Mike Hesson. Number one is Ravi Shastri as all of you were expecting... (But) It was a very close race," said Dev, adding that all the candidates were "excellent".
After missing out on the coach's job to Anil Kumble in 2016, Shastri was selected as the team's head coach a year later for a term extending to the end of the 2019 World Cup.
He was given a 45-day extension for the current West Indies tour.
Shastri coached India to a historic first-ever test series win in Australia earlier this year following Test losses in South Africa and England.
But India's semi-final exit in the 50-over World Cup following their loss to New Zealand last month brought speculation that Shastri's tenure would be brought to an end.
Since Shastri took the job, India have won 13 Tests out of 21, 25 out of 36 T20 matches and 43 out of 60 ODIs.
His next assignment will be the home series against South Africa, who will play three T20 internationals and three Tests starting next month.
Shastri was an all-rounder best known as part of the India's World Cup-winning squad in 1983 and his man of the series performance in India's World Championship triumph in Australia in 1985.
He was also team director from 2014 to 2016.
Shastri played 80 Tests and 150 one-day internationals for India before becoming a successful TV commentator.