Beowulf is an altruistic hero, unusual for the warriors of the day. In his exploits, Beowulf usually fought for others, not for his own glory; while he understood that his glory would be remembered, that was not the main goal of his adventures. In his final battle against the dragon, Beowulf is again fighting for his people, not for himself; he knows that the dragon is too mighty even for an army, and so he faces it with only eleven men, all of whom save Wiglaf flee in the face of real danger.
Beowulf spake then,
Boast-words uttered -- the latest occasion:
"I braved in my youth-days battles unnumbered;
Still am I willing the struggle to look for,
Fame-deeds perform, folk-warden prudent,
If the hateful despoiler forth from his cavern
Seeketh me out!"
(Hall, Beowulf, gutenberg.org)
Because he loves his people more than his own life, Beowulf is willing to die in their defense. In fact, he strives to die in battle, not of old age, because he wishes to give his life to his people as fully in his his death as he did in life. Despite the inevitability of Beowulf's personal glory becoming greater because of this battle, this is not his intended goal; instead, Beowulf fights the dragon in the defense of his land and countrymen, knowing that he alone (and Wiglaf, as it turns out) have the power to keep the dragon from burning the whole land.