Etymology
Today it means: Expressing surprise or disbelief. Full definition →
Compare son of a gun.
Etymology from Wiktionary, CC BY-SA 4.0.