The connecting record
statedNaruto · ch. 601
Madara Uchiha beat Gaara in Naruto.
Decided off the page, in the same fight as Tsunade; the five are left near death.
What each of them is ranked on
The winner · Madara Uchiha · rank 4
shippuden
Five Kage at once, then the allied army, then the two protagonists together — the war arc keeps escalating what it puts in front of him and he keeps going through it. The only reason he is not first is that he is removed from the story by betrayal rather than by any of it, which is a statement about Kaguya and not about the people who could not stop him.
shownNaruto · Fourth Shinobi World War arc
Fights the assembled Five Kage simultaneously and defeats them. — 2013
shownNaruto · Fourth Shinobi World War arc
Becomes the Ten-Tails jinchuriki and engages the allied forces. — 2014
Beaten · Gaara · rank 15
The Fifth Kazekage — classic
Made Kage of his village at an age when the protagonist is still failing to be promoted out of the bottom grade, which is the rank system producing two opposite verdicts on people of the same age in the same year. His sand defends without instruction from him, and by the war he is moving enough of it to shield an army rather than a person.
shownNaruto · Chunin Exam arc
His sand intercepts attacks automatically, without conscious effort. — 2001
shownNaruto · Fourth Shinobi World War arc
Commands and shields allied divisions with large-scale sand. — 2013
What this does not settle
One fight in one work. It is the only result the record gives between these two, and it is evidence about that meeting and nothing wider — not a general matchup, not a rematch, and not a ranking of its own.
The ladder above it is argued from everything either of them has been shown doing; this page is argued from one citation.
Where the two disagree, the disagreement is the point, and it stays visible rather than being resolved by whichever of them happens to be on this page.