What happened at the end of the movie?
Basically, Harlock activates the detonators each time and he dies, and logan is replacing him. At this point if you didn't understood, logan is harlock. Although this time, he did not activate the detonators by seeing logan (his younger self) eager for life and merelly having the same dream harlock once had for earth and humanity. At this point, he's steping back in command allowing logan to lead arcadia and the crew. That's why you see 2 of them in the end, and that's why the crew revived and the dark matter came back.

The movie gave you a big hint at the start by saying:
"Far, far in the future... Or perhaps, the distant past..."

Hope it solved the trouble you had with the ending.