Penafiel came into the clash without a win in seven matches, but they must have thought they were on course for all three points when they went 2-0 up inside 20 minutes thanks to Rabiola and Andre Fontes.
However, Antonio Xavier pulled one back from the penalty spot for Maritimo just after the half-hour mark and two goals in as many minutes at the start of the second period from Ebinho and Raul saw the visitors take the lead.
Substitute Moussa Marega extended their advantage with 15 minutes remaining and even though Guedes made it 4-3 a minute from time, Maritimo held on and Penafiel remain bottom.
At the opposite end of the table, leaders Benfica restored their four-point lead at the top with a 3-0 home win over Vitoria Setubal.
Second-placed Porto had closed the gap to one point with a 1-0 win over Vitoria Guimaraes on Friday, but a goal from Jardel and a brace for Lima saw Jorge Jesus' men cruise to victory.
Sporting Braga are four points behind Sporting Lisbon in the race for the third and final UEFA Champions League place following a 2-0 home win over 10-man Arouca.
Braga opened the scoring through Ze Luis' effort in the 20th minute and Arouca's task was made harder when Tinoco was dismissed for receiving a second caution just after the hour.
Substitute Eder made the points safe for the home side five minutes from time as Braga claimed their third straight league win.
Elsewhere, Academica's Salim Cisse and Boavista's Tengarrinha were both sent off in their goalless draw, while Rio Ave drew 1-1 at home with Moreirense.
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.