Sanjeev Chada, from Bagenalstown, County Carlow, was due to go on trial for the murders of his 10-year-old son Eoghan and five-year-old son Ruairi.
The boys' bodies were discovered in the boot of their father's car after it crashed into a wall near Westport, County Mayo, on 29 July 2013.
Chada, 44, was due to go on trial next month, but pleaded guilty to both murders at a Dublin court on Tuesday.
He has been sentenced to life in prison.
The Central Criminal Court was told Chada had been gambling on the stock market for years and had mounted huge debts from online trading.
Before he carried out the killings, he was facing an investigation for using thousands of euros from community funds to pay for his stock market deals.
The court heard he feared his marriage was going to end and, because he did not want his children to grow up in a "broken home", he planned to kill them both before taking his own life.
The court was told Chada had written a number of notes before he killed his sons and attempted suicide.
In one of the notes, he wrote: "I could not let you bear the pain of being from a broken home. Mammy is getting rid of me and I could not leave you behind."
In a victim impact statement, the boys' mother said her children had died in a "cruel and violent way by their own father".
She added that she had no doubt that 10-year-old son Eoghan had fought to save himself and his younger brother on the day they were murdered.
She said she had trusted her husband and he had been a "hero" to both their sons.
The court was told Chada has been detained in Dublin's Central Mental Hospital.
A man has admitted murdering his two children in the Republic of Ireland.