The final words before he died
Luke alone records the actual last sentence: "And when Jesus had cried with a loud voice, he said, Father, into thy hands I commend my spirit: and having said thus, he gave up the ghost" (Luke 23:46). The words come from Psalm 31:5 and are a prayer of committal to the Father.
John places "It is finished" immediately before the same moment: "When Jesus therefore had received the vinegar, he said, It is finished: and he bowed his head, and gave up the ghost" (John 19:30). Matthew and Mark record that Jesus "cried again with a loud voice" before yielding up the ghost without quoting the final words, which harmonises with the loud cry Luke quotes.
The seven sayings from the cross
Taken together, the four Gospels preserve seven sayings. In their commonly received order: (1) "Father, forgive them; for they know not what they do" (Luke 23:34). (2) "Verily I say unto thee, To day shalt thou be with me in paradise" (Luke 23:43). (3) "Woman, behold thy son… Behold thy mother" (John 19:26–27). (4) "Eli, Eli, lama sabachthani? … My God, my God, why hast thou forsaken me?" (Matthew 27:46; Mark 15:34). (5) "I thirst" (John 19:28). (6) "It is finished" (John 19:30). (7) "Father, into thy hands I commend my spirit" (Luke 23:46).
No single Gospel records all seven. Matthew and Mark preserve the cry of dereliction; Luke preserves the first, second, and last sayings; John preserves the words to Mary and the beloved disciple, the thirst, and "It is finished."
Comparing the four accounts
The four accounts agree on the sequence of events around the death: darkness over the land from the sixth to the ninth hour, a loud voice, the yielding up of the spirit, and the rending of the temple veil (Matthew 27:45–51; Mark 15:33–38; Luke 23:44–46; John 19:28–30).
Each writer selects the words that serve his account: Matthew and Mark emphasise the forsakenness fulfilling Psalm 22, Luke the Son’s trust in the Father, and John the completion of the work the Father gave him to do.