The "real" Tom Sawyer was a heavy-drinking firefighter and local hero whom Mark Twain befriended in the 1860s, according to new analysis by the Smithsonian magazine.

The renowned American monthly attempts in its latest issue to settle once and for all a question that has long perplexed scholars: did Twain really name his child hero Tom after his drinking partner Sawyer, a "stocky, round-faced … customs inspector, volunteer fireman, special policeman and bona fide local hero?"

The pair met in the steam rooms in San Francisco in 1863, writes Robert Graysmith in the Smithsonian, where Sawyer recounted the incredible story of how he had saved dozens of people from a shipwrecked steamer off Baja California – a story close to Twain's heart as his brother had been killed by a steamboat explosion. Sawyer swam back and forth between the ship and the shore, "a feat of amazing strength and stamina", and is credited with saving 90 lives at sea, 26 singlehandedly.

"Twain, floating in clouds of steam at Stahle's baths, was riveted by Sawyer's story," writes Graysmith, and the pair went on to become friends. "Sam was a dandy, he was," Graysmith quotes Sawyer as saying about Twain, whose real name was Samuel Clemens. "He could drink more and talk more than any feller I ever seen," said Sawyer. "He'd set down and take a drink and then he'd begin to tell us some joke or another. And then when somebody'd buy him another drink, he'd keep up all day. Once he got started, he'd set there till morning telling yarns."

In between drinks, Twain was working as a journalist and writing stories anonymously; Sawyer had plans, later fulfilled, to open a saloon. One morning, according to Graysmith, after a "momentous bender", Twain told his friend: "Tom, I'm going to write a book about a boy and the kind I have in mind was just about the toughest boy in the world. Tom, he was just such a boy as you must have been … How many copies will you take, Tom, half cash?"

In 1866, Twain left San Francisco, aged 31, and the pair never met again. The author published The Adventures of Tom Sawyer in 1876, saying the character was based on three boys. He later said that he himself was the inspiration behind the character, and that Tom Sawyer "was not the real name … of any person I ever knew, so far as I can remember".

"The great appropriator liked to pretend his characters sprang fully grown from his fertile mind. Yet the fireman had no doubt that he was the inspiration for the name of Tom Sawyer," writes Graysmith. The belief that Twain named his character after his friend was never disputed while they were both alive.

Graysmith also quotes a 1898 newspaper article in which Sawyer told a reporter about the influence he had had on Twain's most famous novel.

"You want to know how I came to figure in his books, do you?" Sawyer asked in the interview, cited by Graysmith. "Well, as I said, we both was fond of telling stories and spinning yarns. Sam, he was mighty fond of children's doings and whenever he'd see any little fellers a-fighting on the street, he'd always stop and watch 'em and then he'd come up to the Blue Wing [saloon] and describe the whole doings and then I'd try and beat his yarn by telling him of the antics I used to play when I was a kid and say, 'I don't believe there ever was such another little devil ever lived as I was.'

"Sam, he would listen to these pranks of mine with great interest and he'd occasionally take 'em down in his notebook. One day he says to me: 'I am going to put you between the covers of a book some of these days, Tom.' 'Go ahead, Sam,' I said, 'but don't disgrace my name'."

The affection in which his namesake is held today suggests that his friend took him at his word.