Police officers turned up at the writer’s home to question him after a report was made to police that there was a man acting suspiciously on his street.
When the officers arrived at the scene in Edinburgh’s affluent Merchiston area, a resident told them their description of the suspected prowler sounded very much like Rankin.
They then went to the Fife-born 56-year-old’s home and realised it was a false alarm.
It turned out he had been helping his son Jack, 24, move house and was reported to police after someone saw him carrying bags filled with computer equipment.
The award-winning author, famous for his novels about Edinburgh detective John Rebus, revealed on Twitter how the incident unfolded on Saturday afternoon.
He said: “Two cops at the door. Someone suspicious in neighbourhood. ‘From the description, a neighbour thought it might be you.’
“It was actually me and Jack, acting suspiciously apparently, walking down the street we live on.
“I’d just been helping son move from his flat, so all cops could see behind me were boxes, stuffed bags and computer stuff. Suspicious? Moi?
“So it was just me walking down the street. Suspiciously so, it seems.”
Rankin said the two officers “laughed it off” after it was discovered there had been a mistake.
Fellow authors were quick to sympathise with him after he shared the tale with his 102,000 followers.
Crime writer Sarah Hilary said: “Neighbours... Everybody needs good neighbours.
“Oh dear. Were you able to explain yourself to the police?”
Outlander author Diana Gabaldon said: “Do they have the ‘See something, say something’ thing in the UK?,” in reference to the US-based campaign to encourage members of the public to report suspicious activity.
The area where Rankin lives was once dubbed ‘Writer’s Row’ as Alexander McCall Smith, who wrote the No 1 Ladies Detective Agency series, lives nearby and Harry Potter author JK Rowling used to own a home there.
In 2009, Rankin appealed for help online to help police catch vandals who had set fire to five wheelie bins in the street.
It emerged last month that Rankin and other Scottish crime writers dined with Police Scotland chief constable Phil Gormley at the prestigious Royal Scots Club in Edinburgh to discuss the single police force.
He said it came after fellow writers raised concerns with police top brass that a force revamp meant old-school fictional detective heroes would no longer ring true.
Rankin said: “The chief constable did have quite a lot of crime writers in for a meeting. We said, ‘Look this is a nightmare’, and he said, ‘This has all been done for the right reasons and I’m sure you can find a way round it’.
“Trying to explain that to readers all over the world, for most of whom it is an inconvenience, trying to explain that has happened, without boring them with the detail of that, is quite tough.
“Crime writers will tell you how horrified we were when the changes took place.”
Gormley has since said that he did not disclose any “state secrets” during the meeting.