O'Neill started the job in 2013 and led Ireland to Euro 2016, where they were defeated 2-1 by eventual finalists France in the first knockout round.
The 65-year-old had previously made no secret of his desire to renew and said earlier on Thursday in a media conference that both sides were eager to find an agreement.
O'Neill's renewal secures his immediate future despite Ireland sitting in a potentially precarious position in World Cup qualifying, positioned in third place in Group D behind Serbia and Wales with two matches to go.
Defeat at home to rock-bottom Moldova on Friday could end their qualification hopes should Wales beat Georgia earlier on the same day, but clearly O'Neill and Ireland are looking beyond next year's World Cup.
BREAKING: Martin O'Neill has agreed a contract extension and will continue as the Republic of Ireland manager for the EURO 2020 campaign! pic.twitter.com/UAjiKoMGVh— FAIreland (@FAIreland) October 5, 2017
Speaking to the national team's official website, O'Neill said: "I spoke to John [Delaney, chief executive] very recently and he said on behalf of the board that he wanted to extend my contract for the next couple of years.
"Obviously with Euro 2020 coming up, I've agreed to do so. I've enjoyed it [as manager] immensely.
"I wasn't sure If I would get used to international football or not, but qualifying for the Euros [Euro 2016] made it all worthwhile and we're still in this competition [World Cup qualifying] also.
"The future, now with some younger players coming through and taking over from the old guard who will retire naturally through old age as much as anything else, I think makes it an exciting time for us."