England, who were 70 for four soon after lunch, had moved on to 171 for five when rain prevented any play after tea and forced an early close to an intriguing opening day in the 75th Test staged at Headingley.
Opening batsman Hales, under pressure for his place after a modest return in England’s series win in South Africa, was a Test-best 71 not out with Bairstow, on his Yorkshire home ground, unbeaten on 54.
The pair’s so far unbroken sixth-wicket partnership of 88 helped England recover after Shanaka’s treble strike helped justify Sri Lanka captain Angelo Mathews’s decision to field first.
Mathews won the toss in overcast conditions reminiscent of those at Headingley two years ago when his side triumphed in the second Test to seal their first series win in England.
England captain Alastair Cook, who started his innings needing just 36 more runs to become the first Englishman to score 10,000 in Tests, got off the mark with a trademark clip off his legs for four.
But the left-handed opener was caught behind for 16 going for a cover drive off a wide but full delivery from Shanaka.
Three deliveries later and still in the 21st over, Shanaka had the under-fire Nick Compton out for nought with first slip Lahiru Thirimanne holding a low catch.
Joe Root, England’s recently crowned player of the year in all formats, also fell for a duck to Shanaka as he edged to gully.
Shanaka, who scored a hundred in Sri Lanka’s final warm-up match without hinting at his worth as a bowler, had taken three wickets for one run in eight balls.
The 24-year-old’s return again proved the value of accurate medium pace in conditions offering some assistance, if not extravagant movement, for swing and seam bowling.
England were 57 for three at lunch.
Hales was then 38 not out, with debutant James Vince unbeaten on nought.
After getting off the mark Vince, 25, whose elegant style has been compared to that of Michael Vaughan, struck two fours — a cover-drive and straight drive — worthy of the former England skipper.
But Vince, who recently scored a hundred at Headingley for Hampshire against county champions Yorkshire, exited for nine when he nicked Shaminda Eranga, to gully.
All-rounder Ben Stokes struck three fours but holed out tamely to mid-on off Nuwan Pradeep.
Hales completed an admirable 112-ball fifty in the circumstances when he drove Dushmantha Chameera behind point for his 10th four.
Since former captain Andrew Strauss retired four years ago, eight batsmen — including Hales — have had spells as Cook’s opening partner without making the position their own.
But Thursday saw Hales, whose previous Test best score of 60 came against South Africa at Cape Town in January, demonstrate he could rein himself in when the bowlers were on top.
Bairstow was given out lbw on 41 but successfully reviewed the decision and soon afterwards lofted spinner Rangana Herath for six.
Sri Lanka then reviewed a not out call in favour of the wicket-keeper when Herath’s lbw appeal was rejected, with replays again favouring Bairstow.
Players from both sides wore back armbands in memory of all those killed by recent flooding and landslides in Sri Lanka.
Know more about Sport360 Application