Aberdeen Grammar have given themselves a chance of escaping relegation after grabbing a vital losing bonus point to move off the bottom of the league.
However, they were aggrieved at being denied an added-time winner when referee John Shaw adjudged prop Matthias Schosser had knocked on when over the try line.
Coach Stuart Corsar said: "It was hard to take but we should never have been in the position of chasing the game after turning round 17-0 down. We need to hit the ground running in our remaining five games. I'm sure we will save our season."
For 40 minutes it looked the same old story as Grammar struggled to contain a fluent and organised Accies, who were a penalty and a converted try up in 20 minutes.
Accies were playing with a strong breeze but had to wait until a minute before half-time for hooker Callum Black to add a try to the penalty from stand off William Stephen and the touchdown of lock Greg Campbell. Stephen added the conversion, as he had done in the 20th minute, giving the visitors a 17-0 lead at the break.
Grammar's players pulled themselves together, inspired by an early long-range penalty from captain and stand off Alex Hagart, and took the play deep into the Accies 22. But they failed to breach the visitors' line, settling instead for another well-struck Hagart penalty in the 63rd minute.
Three minutes later Hagart chipped over the opposing defence for Grammar's most enterprising player Peceli Nacamavuto to score in the corner. Hagart kicked the fifficult conversion and it was game on at 17-13.
Ten minutes from time and in their only serious attack, Accies caught the home defence napping, enabling scrum half Alex Glashan to race over for an unconverted try.
Grammar rallied three minutes from time when Hagart raced through to make it 22-18 but he failed with the conversion.
Grammar looked to have dramatically won the game when Schosser barged over from a lineout, only for the officials to pull him back for a knock-on.
Hagart was defiant in defeat and said: "The losing bonus point could yet be vital. It was our most complete team performance for a while. I believe we will turn things round."
Grammar will not be in action until March 5 when they travel to Edinburgh to play leaders Watsonians.
© Jack Nixon
Aberdeen Grammar: Alex Ratcliffe; Grant Walker, John Poe, Peceli Nacamavuto, Martin McRobbie; Alex Hgaart, Sam Knudson; Colin Neilson, Stuart Davis, Matthias Schosser; Hamilton Burr, Robin Cessford; James Spalding, Tony McGinness, Adrian Hamilton.
Replacements: Chris Prentice, Calum Champion, Matthew Reid, Andrew Ovenstone, Doug Russell.
Edinburgh Accies: Kieran Scoular; Josh Pecquer, Ewen Campbell, Iain Berthinussen, Neil Armstrong; William Stephen, Alex Glashan; Connor McGrath, Callum Black, Clement Lacour; Greg Campbell, Ronan Seydak; Jamie Winks, Jamie Sole, Lawrie Seydak.
Replacements: Mark Latta, Murdo Patterson, Tom Drennan, Max Love, James Evans.