The two sides had both beaten each other once in Division 4 East Central this season, where Tonyrefail finished second and earned promotion while Ferndale finished third.
Ferndale had triumphed 22-20 at Tonyrefail in the last meeting between the sides on 23 March, and they were victorious again as the sides went head-to-head in the final.
Outside centre Zen Bevan and scrum-half Sam Hodder scored for Ferndale. Right wing Evan Wheeler converted Hodder’s try and sent over four penalties.
Full-back Garreg Lewis went over for Tonyrefail’s try, converted by outside half Jordan Jones, who also kicked two penalties.
It meant that Ferndale – who were promoted as champions of Division 5 East Central last season as well as reaching the Principality Stadium in the WRU Division 5 Cup – also ended this campaign with a trophy.
Head coach Marc Whitford had stepped down after leading his side to glory last season but returned in November after a difficult start to life in Division 4 for the side.
After losing 29-5 at home against Tonyrefail on the opening weekend, Ferndale picked up just one win from their opening six league games, drawing one and losing four.
But they pulled together and lost just once since 9 December and ended the season with seven successive wins, guided by Whitford and other coaches Jamie Wicks and Ceri Bessant.
“It’s an outstanding achievement for the boys. I left last season due to personal reasons but went back in November,” said Whitford after the game.
“They had a tough time of it at the start of the season, but the boys have just pulled together tight. To finish the season third in the league and win this cup is a massive achievement for the club and community.
“We’ve got to give credit to Tonyrefail, they’ve been promoted, but for us a Rhondda derby is something special and we look forward to these challenges.”
Ferndale were never behind in the final, with Bevan’s unconverted try and three Wheeler penalties giving them a 14-6 half time lead. Tonyrefail responded with two Jordan Jones penalties.
Hodder’s try in the second half, converted by Wheeler, sealed it despite Tonyrefail threatening a comeback when Lewis went over for a converted try with just under 10 minutes remaining.
The final word went to Wheeler with his fourth penalty three minutes from time.