Agar, who has been head coach of the Black and Whites since May 2008, will see out the season before leaving to take up another appointment – believed to be at Wakefield Trinity Wildcats.
McRae, who was head coach at Hull from 2000-04, will become the club’s director of rugby and help choose Agar’s successor.
That is expected to be Australian Peter Gentle, currently assistant to Tim Sheens with both Wests Tigers and Australia, who rejected the chance to take over as Salford coach earlier this year.
The departure of Agar comes six weeks after the club was taken over by Hull City FC’s Adam Pearson.
McRae, who recently left his post at Salford due to ill-health, said: “I am delighted to be returning to Hull FC and I am honoured to be part of the exciting times that lie ahead.”
McRae uniquely held the position of head coach throughout the first nine years of Super League.
The 51-year-old Australian was in charge of St Helens for the first three seasons and had a 12-month stint at Gateshead before taking over at Hull following their merger with the Black and Whites in 2000.
He left at the end of the 2004 season to become head coach of South Sydney but returned to England to succeed Karl Harrison at Salford in 2007 and only relinquished the post earlier this year due to stress.
McRae, who will become a director of Hull FC and be responsible for all aspects of the playing side, will officially take up his duties on October 1 but will oversee the appointment of a new coach before then.
“I look forward to working with Adam Pearson and all the staff and players and also re-acquainting myself with the ‘old faithful’,” he added.
Agar joined Hull in 2005 as assistant to McRae’s successor John Kear and took over from Peter Sharp three years later, guiding the Black and Whites to a Challenge Cup final appearance in 2008.
He is now set to succeed Kear at Wakefield after emerging from a seven-strong shortlist of names, with confirmation expected before the Wildcats’ last match of the season against Bradford on Friday.
Agar, whose side take on Warrington at the KC Stadium on Friday, said: “It has been a fantastic experience to work for Hull FC over the last seven years.
“I consider it an honour to have worked with the players and staff of this great club. I leave with pride that we have built a quality squad and culture.
“I would like to wish the directors, players, staff and fans all the very best for the future.”
A Hull spokesman said: “The board would like to place on record their heartfelt thanks for the excellent job Richard has done during his entire seven years at Hull FC, but particularly for his time as head coach.
“Richard leaves the club with an excellent squad now and for next year, as well as a club in financial good order.
“Without a great deal of transferfee kitty at his disposal he has built a squad that has a real chance of silverware now and in the very near future.”
Huddersfield will part company with half-back or full-back Gregg McNally and hooker Keal Carlile after deciding not to offer them contracts for 2012.
McNally, 20, and Carlile, 21, joined the Giants from Whitehaven and Bradford respectively in 2009 but have made just four Super League appearances between them.
Castleford will be without full-back Ryan McGoldrick for their Super League match against Hull KR on Saturday. The Australian has been handed a two-match ban and a £300 fine after being found guilty of striking Hull half-back Sam Obst during his side’s 50-18 defeat last Saturday.
Wigan’s controversial forward Gareth Hock will miss the rest of the season after being handed a five-match ban for gouging an opponent last weekend.