After a training session in Melbourne ahead of the fourth Ashes Test starting on Boxing Day, McGrath, 36, announced that the Sydney Test match next month, on his home cricket ground, would be his last five-day game.
"It's probably a perfect or fitting ending," McGrath said on Saturday.
"It's only been the last few games that I've really thought about it."
McGrath's announcement comes just two days after spin king Warne revealed he would give up international competition after the Sydney Test.
"To me it feels like the right time to go and I've trusted my instinct in the past and I feel it's time to trust it again," McGrath said.
However, he said he would continue playing one-day internationals for another four months, playing his last limited-overs games at the World Cup in the Caribbean, which runs from March 11 to April 28, before quitting all forms of cricket.
Having taken 555 wickets in 122 Tests since debuting against New Zealand in 1993, McGrath is third on the list of all-time wicket-takers behind only Warne (699) and Sri Lankan offspinner Muttiah Muralitharan (674).
McGrath's decision to up stumps on the game clears up recent frenzied speculation that he would leave the sport after the Ashes series to spend more time with his family.
He spent most of 2006 out of international cricket to be with wife Jane in her battle against cancer.
However, McGrath said his wife's illness had played no part in his decision, which, along with Warne's announcement, comes less than a fortnight after batsman Damien Martyn, 35, called time on his cricket career.
"In respect to Jane, her health has nothing to do the decision I've made here today or over the last few weeks."
He also said that the niggling injuries that had dogged his career for the past three years were not a factor in his retirement.
"I have no doubts that I could have continued on probably for another couple of years.
"The body's feeling as good as it ever has, recovering well. I've sort of surprised myself (by) how well I'm pulling up."
Although McGrath was coy Friday on reports of his imminent revelation, he said Saturday that the past days' rumours had forced him to make an announcement earlier than he had expected.
He said: "The plan we came up with was for Shane to announce it before the Melbourne game and I was going to announce it before Sydney.
"(But) with the scrutiny and the hearsay and what's happened mainly in the last few days, I wanted to get it out in the open, get it over and done with, basically, so we could get back and concentrate on the last two Tests."
He added: "With all good plans, they're good in theory but they don't seem to work."
McGrath said he and Warne had considered delaying their announcements in the event of Australia drawing or losing the most recent Test, in Perth, where their success clinched the return of the Ashes.
"Hopefully Shane and I coming out now, it's not a distraction for the last two Tests," he said.
"I think the timing of it couldn't be more perfect for both Shane and I."
McGrath said he looked forward to playing the remainder of the Ashes now that his announcement was off his chest.
"Hopefully we can get out there and play as well as we have for the whole summer and really nail these last two Tests."
While the rash of departures leaves a gaping hole in the Australian cricket side, McGrath said there was plenty of talent waiting in the wings to take his place.
He said the hard gap to fill would be that left by Warne, whom he described as the best cricketer he had played with.
"To me he's one of the best cricketers there's been."