diff --git a/examples/main_fof.c b/examples/main_fof.c
index cee267df9e79332b26fb882333f5272d2a55d80b..e1e2d73e1452b001f99f913752124d57c0275a8c 100644
--- a/examples/main_fof.c
+++ b/examples/main_fof.c
@@ -1077,6 +1077,11 @@ int main(int argc, char *argv[]) {
   engine_print_stats(&e);
   engine_dump_snapshot(&e);
 
+#ifdef WITH_MPI
+  if ((res = MPI_Finalize()) != MPI_SUCCESS)
+    error("call to MPI_Finalize failed with error %i.", res);
+#endif
+
   /* Clean everything */
   if (with_verbose_timers) timers_close_file();
   if (with_cosmology) cosmology_clean(&cosmo);