I know that もちろん is often used to mean something like "of course (you may)" or even "naturally, ..." However, what would an equivalent expression be for "of course!", used as an interjection as a result of sudden realization or comprehension? For some reason, もちろん doesn't seem right, and I don't believe I've ever heard or seen it used in this context.
I think the following come closest
when you realize something you didn't anticipate (or at least you pretend not to have anticipated, e.g. when you are being polite):
Of course! I never noticed!
when you had confirmed something you did anticipate:
Of course! I knew it!
Some quick impressions:
- そっか： Oh, is that so?
- やはり / やっぱり： I suspected that all along.
- まさか / まじっ： No shit!
- あった： Yay!
I have also heard "あった！" used in this context. Which I assume to be a contracted/casual form of "当たり".