The Island was a real island. Everything which took place there really happened. The only part that took place in the afterlife was the "Sideways" universe.
When they set off the bomb they created the conditions that led to the hatch being what it was when they encountered it in the first place and sent themselves to the right point in time. Had they not counteracted the EM release with the bomb, the island would have been destroyed, if Faraday was correct.
Wanting to finally leave the island, the smoke monster followed Jack to the heart of the island, as only the protector of the island can locate it. Desmond was the only person who could get close to the stone cork inside the heart due to his unique resistance caused by his time in the swan hatch and its explosion in season 2.
The man in black took advantage of this and used desmond to pull the cork out thinking it would destroy the Island (it would have) Jack went along with MIB's plan, hoping he could figure out a way to kill him. desmond pulls the cork, and MIB is rendered mortal to his surprise, Jack and Kate take advantage and finish him off for good. then Jack puts the cork back where it was to save the island, and ends up dying from his stab wound in the same place where he first woke up on the Island.
We find out that in the afterlife, the Losties have been experiencing a collective consciousness pseudo-time line they "created for themselves" so they could all go on to Heaven together.
In the church, there is no time. Everyone experienced this entire "time line" in the seconds before their death, regardless of when they died. Hence Juliet experiencing it as she died in Sawyer's arms and Jack experiencing it as he died in the bamboo forest. Hugo and Ben had memories of running the Island together, but they eventually die and move on. When they do they have a big Island party before they "move on."