Noun: any fortunate event or achievement that is a result of luck.
Verb: To achieve something good or end up in some good circumstance by sheer luck.
The term has its origins in the Spanish verb "cagar" which means "to take a crap, to shit, to defacate".
In English, when something lucky happens or is accomplished, one might say that it was "pulled out of (a person's) ass". The idea is the same with "cag".
He made that shot from halfcourt and won the game. What a cag!
You didn't study and still managed to get an A on the test. You cagged out.