There are many details missing here, esp. regarding the table play to that point (loose/tight), quality of players, your image etc.
Hindsight here is 20/20, so I'll try not let that to influence what I'm about to wrote.
But in general, I find that opening a pot with a 4x BB, UTG w/ 99 is a over-betting a medium pair. That is, you have:
* Put more money into the pot than the hand is worth
* many players behind you, and you are inviting multiple calls, which you don't want w/99
* you are also inviting a big reraise against a stronger pocket pair (and you've got 8 betters behind you!); often someone holding AA/KK will raise moderately (like your 4x opener) into limping callers to drive out the weak and isolate the strong HU, but not cause all players to fold. They want a caller, possibly two. However, when those same hands see a strong, early re-raise, they will raise much bigger (10x+), calculating that you have a strong hand (you don't, BTW) and will call. They're sucking you into a bigger pot.
99 will fare poorly if an overcard flops. You want, ideally, either a big pot heads up, where you are 53% vs. 47% against a pair of overcards, or to see a **cheap** multiplayer pot and hope to flop the set.
As to your flop play, your set is 2nd nuts, but, *** given the apparant looseness of this table***, flopping the straight is not out of the question, nor is a very aggressive semi-bluff (which is what happened).
Checking and calling AllIn, I think, is correct. That villian raised AI w/ weak 2nd pair and gutshot is a "mistake that paid". File that one under "Donkeys Have to Eat Too" and make a note of this players poor play.