The Championship side's never say die attitude meant they were always in the game and the two sides went into the break level at 13-13.
And when Josh Lewis added three second half penalties, the Steelmen led a rattled Pontypridd side 22-16 with seven minutes remaining.
But with his side in dire straights and seemingly heading out of the cup, Pontypridd skipper stood up to be counted as he crossed for a late try. The conversion still needed to be nailed but Flanagan did so with aplomb to secure a 22-23 win and set up a semi-final clash with Carmarthen Quins.
"This has been the toughest encounter we have been through all season," said Pontypridd head coach Dale McIntosh at the final whistle.
"We did not play as well as we could or should have but that is down to the sheer commitment of the opposition.
"The accolades will go to Ebbw Vale today despite their defeat but on our part we showed great character and resolve which saw us through right at the end. That is what great cup games like this come down to."
"We can be proud of the win even if by only one point," added skipper Dicomidis.
"We tended to panic under the significant pressure that Ebbw Vale put on us and could not play in the manner that we are accustomed to. In a cup quarter final only one thing matters and that is the letter 'W' which has taken us through into the next round."
Before the late drama Simon Humberstone and Lewis had exchanged early penalties before the visitors opened the scoring with a superb score. Gareth Wyatt and Owen Williams combined to put Dicomidis through a hole before the ball was shipped on.
Humberstone then fed centre Dafydd Lockyer who raced over for a scintillating try. The Pontypridd fly half then kicked the extra two as his side went into the lead.
But Lewis responded with a penalty of his own before setting up and converting a try for wing Luke Davies.
Humberstone made sure things were level at the break but it was the Steelmen who were on top in the second period as they rattled their Premiership opposition.
Lewis pushed them further clear and it looked like an upset was on the cards.
But in a dramatic finale, Dicomidis and Flanagan combined to leave Ebbv Vale head coach Jason Strange disappointed.
"We were six points up and in the last quarter but then we had three players injured, including fly-half Josh Lewis," he said.
"In fairness, I could ask no more from my players and I was proud of them. After all, we were playing against the best club in Wales."