But after a string of good saves from Preston’s Daniel Iversen, McAvoy celebrated three points after two late goals inside four minutes.
Ched Evans, who played under Wilder at Sheffield United, headed Preston level 13 minutes from time before Emil Riis was gifted the winner soon after to prevent a third straight defeat.
Wilder had watched his new side record a point against Millwall four days earlier, but it is now five without a win for the Teessiders who were leapfrogged by Preston into 14th.
Middlesbrough have ‘cooled’ interest in Norwegian ace, Nottingham Forest make ‘opening bid’ for Watford star
Paul Hartley hints at possible transfer breakthrough for Hartlepool United
Middlesbrough transfer news: Boro to battle local rivals for Man City forward, Coventry City play down Everton interest
This is why Hartlepool United's ex-Luton Town defender missed Blackburn Rovers defeat
Paul Hartley reacts to Hartlepool United's heavy defeat to Blackburn Rovers in the Carabao Cup
With goalscoring chances initially scarce, Middlesbrough were fortunate not to have conceded a penalty when Marcus Tavernier shoved Riis as he charged into the area.
Referee Andy Woolmer waved play on despite complaints from the visiting bench.
That proved a crucial decision too. Shortly after Tavernier whipped a beautiful ball across the face of goal that Duncan Watmore was inches away from getting on the end of, Middlesbrough went ahead.
Jonny Howson took over corner-taking duties from centre-back McNair and that move proved pivotal because the latter’s thunderous header from the delivery crashed in off the underside of the bar.
Before the break Preston had a second penalty appeal waved away when Isaiah Jones slid in and Josh Earl fell to the floor, with white shirts surrounding the referee.
And with seconds remaining of the first half Preston goalkeeper Iversen made a stunning save to prevent Watmore from making it two with a chip from 20 yards.
Overlapping centre-back Lee Peltier was next to go close early in the second half when he turned on to his right foot and curled an effort against the woodwork.
After that Preston had struggled to make an impression in the attacking third and it seemed a question of whether Middlesbrough would extend the lead.
McNair’s curling free-kick from 25 yards forced a save from Iversen, who shortly after denied Onel Hernandez a goal too with his feet.
Iversen was then called into action to palm away a low drive from Andraz Sporar and those saves paved the way for the surprise turnaround.
Ben Whiteman sent over the corner in the 77th minute and Evans rose in a crowded area to head inside Luke Daniels’ top left corner for his first of the season.
And after the referee waved away a handball claim when Tavernier’s effort was blocked in the penalty area, Preston countered and were gifted the winner.
Sol Bamba’s lazy pass in his own box deflected off McNair and dropped to Riis.
The Dane controlled before curling his eighth of the campaign beyond Daniels with nine minutes left to frustrate the Riverside crowd.