He kept saying he did not do it but 'in the end' he said he had done it.

Answer: 
finally
He kept saying he did not do it but 'in the end' he said he had done it.