As Obama was casting his ballot at the Martin Luther King Junior community centre in Chicago Monday, he was standing beside a woman, Aia Cooper, whose boyfriend - Mike Jones - approached them and said jokingly to the President: "Mr. President, don't touch my girlfriend."
"I really wasn't planning on it," Obama responded in a repartee, the reports said Tuesday.
Clearly embarrassed, Cooper apologised for her boyfriend's behaviour, telling Obama that she knew he was going to "say something smart", but she did not know what.
Jones later justified his remark to reporters, saying that everyone was so quiet that he thought he had to say something to "make people laugh".
The President took the joke in good humour and after voting gave Cooper a friendly hug and a kiss on the cheek.
The President showed up at the community centre by surprise Monday morning. The site is near the house where he lived until the time he was elected the President in 2008.