Most agree that the Pug originated in China, dating back to around 700 BC. They were bred to be a companion not a guardian. They were bred by the royalty and were pampered and spoiled. They have not lost this characteristic. Sometimes, as a mark of great esteem,they were given to members of the court.
Some interesting antidotal history (not officially verified but worth mentioning) includes an ancient Chinese law whereby only the Emperor was allowed to own a Pug. He could give a Pug to his own selected friends but otherwise it was punishable by death to have a Pug. True or not most Pugs feel quite highly about themselves and will encourage everyone and anyone to treat them like an Emperor's dog!
When the Dutch discovered and started trading with China, the sailors smuggled some out and took them home to Europe where being a small dog and natural companion, they quickly became popular. Again, they attached themselves to the nobility. Pugs are great opportunists.
The legend has it that when William The Silent invaded England, he took his Pug with him. One night, as the Prince lay sleeping, assassins crept up on his tent. His Pug heard them and jumped up barking, thereby saving his master.
Another 'story' involves the 'love affair' between Napoleon and Josephine. It seems Josephine came part and parcel with her dearly beloved Pug. Well her Pug did not want to share a pillow with Napoleon and bit him (not a normal Pug trait but hey Napoleon was a tough guy!). Now Napoleon was not known for forgiveness and had killed man and beast for less.
Well the story goes that Josephine made it clear the Pug was there to stay and if she had to choose between the Pug and Napoleon - well, there's the door Napoleon. The Pug and Napoleon worked out a truce. He conquered most of Europe but not a PUG!