An early Hadi Noori gave Klubi the lead before Arvid Lundberg equalised for Mariehamn before the break.
However, a Max Peterson own goal and strikes from Mustafa Ameen and Liam Rippon put the second-tier side firmly in control against the side sitting ninth in the Finnish top flight, before Jayden Reid scored two consolations in added time for Mariehamn, both from the penalty spot.
HJK have also made it to the last eight, but will not be in quite the same celebratory mood after labouring to a 1-0 win away at Mikkeli, one of four third-tier side to reach the last 16, as David Ezeh scored the winner early in the second half.
Mikkeli's fellow Ykkonen sides were all eliminated, too - KPV Kokkola were thrashed 7-0 by SJK, for whom Jeremiah Streng and Valentin Gasc both grabbed a brace, while Agon Sadiku and Dion Krasniqi also grabbed two each as cup holders KuPS won 6-2 away at Jazz Pori.
Meanwhile, second-tier Ekenas won 1-0 away at third-tier OLS Oulu to ensure two sides from the Ykkosliiga will play in the Quarter-finals.
In the two all-Veikkausliiga ties, Haka edged out Gnistan 3-2, while VPS were 2-0 up against Jaro before Filip Valencic scored twice for the hosts to make it 2-2 to take the tie to a penalty shootout, which Jaro won 5-4.
On Tuesday, PK-35 came close to an upset away at AC Oulu, before the side struggling at the bottom of the Veikkausliiga took the win on penalties.
Follow the Suomen Cup on Flashscore.