The way Attorney General Griffin B. Bell tells it, Peter F. Flaherty was named Bell's principal deputy through the chance circumstance of being in Washington with some time to kill and deciding to visit a friendly political foe.

"You're not going to believe this," Bell said yesterday in response to a press conference question about how Flaherty, the outgoing mayor of Pittsburgh, was chosen as deputy attorney general.

The appointment has stirred some ripples of controversy because of charges that Flaherty does not have the requisite legal background for the job and was picked as a payoff for his support of Jimmy Carter in the Democratic presidential primaries last year

But, Bell insisted, that wasn't the way it happened at all. In recounting "the real story," he said, "You may recall a Republican fellow named Thornburgh that used to be around here."

That was a reference to Richard L. Thornburgh, one of the Ford administration assistant attorneys general replaced by Bell. Thornburgh also is from Pittsburgh and made his way up in the Justice Department as a U.S. attorney who successfully prosecuted several Democratic politicians in Pennsylvania.

When Bell took over the department, he asked Thornburgh, who headed the Criminal Division, to stay on for a brief transitional period as acting deputy attorney general. That, Bell said, "got me in a lot of trouble. I got a lot of complaints from people in Pennsylvania saying I was helping him to run for governor or something."

But, Bell added, it was Thornburgh who brought Flaherty in to meet him. Flaherty, Bell recalled, had come to Washington early last month with his wife, Nancy, who had been named to the President's Advisory Board on Ambassadorial Appointments. She was attending a White House reception, and Flaherty, who hadn't been invited, had decided to pass the time by paying a call on Thornsburgh.

"I told him about the trouble we were having filling various jobs," Bell said. "I mentioned that one prolem was getting people who would commit themselves to staying in government for a full four years."

"Later," he added, "I got a letter from Mr. Flaherty, applying for the deputy's job and telling me that he was willing to stay the four years.

Bell said he dug into Flaherty's background and found that he'd had extensive criminal law experience as assistant prosecutor in Pittsburgh. "But," Bell added, "what impressed me most was his reputation as a good public administrator. I'd decided that was what we needed in the deputy's job, and that's mainly what I made my decision on."

He conceded though: "I'll have to say that I didn't have any trouble getting him cleared from the White House. The President seemed to know who he was."

Bell said that when he discussed Flaherty with presidential assistant Hamilton Jordan he mentioned that the prospective nominee was an honor graduate of the Notre Dame law school.

"About 15 minutes later, the President called me to second the nomination," Bell recalled. "As we were finishing our talk, he asked me, by the way, did I known that Flaherty was an honor graduate of Notre Dome Law school."