An interjection or exclamation of surprise.
This little term derived in the USA as a euphemistic shorthand for Jesus; in other words it is a minced oath. That original meaning is largely forgotten by those who use it now, who are in any account fewer than before, as it is now sounds rather old-fashioned. The further shortening of simple gee is still widely used in the USA, although neither version was ever common elsewhere.
The first record of it appearing in print is from Cody and Arlington's Life on the Border, 1876:
"Gee-wees!...I'll bet one hundred dollars on that hand!"
The currently accepted spelling was used soon afterwards; for example, this piece of doggerel from the Pennsylvania newspaper The Warren Ledger, 1883:
When younger days have flown
And we are older grown,
We sit and muse -
We've got the blues.
Morning and night we fret,
And, cold or dry or wet.
In petulance pout -
We've got the gout.
We have accomplished naught,
Our fight was poorly fought -