Llanfair started well and were in front after 16 minutes, Richard Astley heading home an in swinging Karl Seliaerts corner from the right.
Berriew should have equalised soon after but after rounding the goalkeeper, an effort was blocked on the line by Matt Spencer.
Berriew equalised just before the break, a great right wing cross by George Davies found Richard Davies unmarked in the box, who looped his header over a stranded Danny Foulkes in goal.
In the second half, Toby Evans was unlucky not to put Llanfair back in front when his long range effort cannoned back off the bar on 55 minutes.
After that, Berriew dominated and will rue a number of missed chances including a penalty on 73 minutes, which Danny Foulkes saved down low to his left.
Berriew hit the crossbar soon after but the missed penalty spurred Llanfair on, along with a number of fresh players on the pitch. Nathan Hughes was agonisingly close with a header in the dying minutes before Josh Astley headed Llanfair back in front from close range, off a neat Max McLaughlin cross from the left.
Berriew will feel very hard done by but it’s Llanfair who progress, facing local rivals Dyffryn Banw in the next round (tie TBC)
Man of the Match - Paul Griffiths