Frankly I think you are probably fubared as I doubt you have time to wall it off, and dorfs will run away if the vomit monster gets within 20 tiles or so of them. If you have an old save file floating around you could try reloading that maybe.
In the future I suggest outfitting your front door with a Titan Swatter. Build about a 3x15 outside corridor with a ceiling above it supported by a support sitting on the wall (see diagram). Link the support to a lever that's situated near one of your meeting halls so there's available jobless dwarves when the time comes. When it does, just wait for the titan to walk into the trap and pull the lever...bam, instant dead titan (or anything else as cave ins kill everything). Megabeasts are slow so this isn't as hard as it sounds. Might be worth putting one near your mine shaft too in case of forgotten beast, but those are more easily avoided or special trap set up just for them. For an added bonus, fill it with cage traps and minor sieges won't be a problem either.
. = open space
M = cliff face
W = wall (w = wall top/implied floor)
F = floor
S = support
[Z=0] [Z+1] [Z+2]
.WWWWWWWWWWWW .wwwwwwwwwwww .............
.W........... .w........... ..FFFFFFFFFFF
.W........... .w........... ..FFFFFFFFFFF
.W........... .w........... ..FFFFFFFFFFF
.W...WWWWWWWW .w...wwSwwwww ..FFF..F.....
.W...W....... .w...w....... ..FFF........
.W...W....... .w...w....... ..FFF........
.W...W....... .w...w....... ..FFF........
.W...W....... .w...w....... .............
MM...MMMMMMMM MM...MMMMMMMM MM...MMMMMMMM
Make sure you deconstruct the access stairs when you're finished (I put them next to the support and deconstruct lower) and that it's not touching the cliff face or anything else--must be supported only by that rigged support. I have successfully used this on multiple otherwise-unkillable titans, works every time. Obviously it takes some time to set up so I don't think it would help your current situation.
Also I suggest you save off your game occasionally, in case something really nasty like this happens you can revert to an earlier save and not lose all your work. Some people on this forum like to QQ about that sort of thing but they're not playing
your game so they can deal with it.
Init options can do this automatically for you, though loading the save is a bit annoying and involeves a bit of directory-diving.