The home side took the lead with a seventh-minute penalty, but Scarborough hit back when Tom Harrison chased through his own kick to cross the try-line, the conversion missed to make it 5-3 to the away team.
Scarborough then conceded a string of penalties and eventually Beverley scored an unconverted try to lead 8-5.
The away side responded well again when Harrison fed Matty Young, who raced clear to score a converted try and put Scarborough 12-8 in front.
Scarborough continued to give away penaltes, prompting skipper Matty Jones to urge his players to cut out the penalties. Fortunately Beverley dragged a penalty wide from halfway.
Scarborough officially smashes temperature record as Met Office confirms new hottest day
Whitby Regatta 2022: Red Arrows unable to display over town as sea fret rolls in
Post-war asbestos bungalows to be demolished in Scarborough as plans for new terraced homes approved
RNLI issue weever fish warning for Yorkshire coast
Whitby Regatta - here's what's going on at this year's event
Harrison then chased down the Beverley defender, winning the line out but Scarborough conceded possession giving another penalty away.
Beverley were dominating the set scrum but Aaron Wilson drew the knock-on, and Scarborough had the chance to clear, the score remaining 12-8 at the break.
The away side took a firm grip of the game after the interval, stretching their lead to 19-8 with an excellent try from Harrison. Scarborough earned a penalty 30 yards out, everyone expected the kick to the corner but Harrison chipped it over the defence and won the race.
Beverley then went on the attack, but Scarborough's defence remained solid and the hosts knocked on.
The away side then secured the bonus point when a lightning break by Scarborough saw Harry Dommet dance round the home defence for the try, converted to put them 26-8 ahead.
Young was then poleaxed by a high tackle, and after lengthy treatment he was helped back onto his feet, but was unable to continue.
The offending player was the Beverley 12 who had only just returned from the sin-bin and was shown the red card.
The win was effectively sealed when a quick tap penalty by Jordan Wakeham fed Tom Ratcliffe to score in the corner to make it 31-8.
The depleted hosts mounted a late revival during 11 minutes of injury-time with two tries, but Scarborough's 31-20 win was enough to put them second in the league table.