In the first Matrix movie Agent Smith and Neo survived the green explosion from inside the agent. But in the third movie Neo and Smith both died as a result of the same attack in the first movie. How did this happen?
It's not the same attack.
In the first movie, Neo enters Smith's code and basically decompiles him from the inside, which presumably destroys him (though we know enough of him survives to resurface with "upgrades" taken from Neo).
In the third movie, Smith overwrites Neo's RSI, which, because Neo is hooked into the Matrix directly from the machine city at the time, gives the machine city the opening they need to pump an antivirus into the Matrix and cleanse all of the Smith-infected code. This purges the Smith code from the Matrix completely, but has the side effect of killing Neo.