The Terminal is the command-line for Mac OS X. It allows you to execute Unix commands directly in a Unix shell. It is not something one should play with lightly, as those commands can be dangerous. You can safely drag it off the Dock, but don't try to delete it if that temptation arises... the Terminal can be an important tool.
As to how it got there, that's hard to say. If you didn't put it there, someone must have. Has anyone else been using your computer, to your knowledge?
I'm guessing (as I think petermac87 is) that you double clicked on something that Mac OS X thought needed to be run in a Terminal session, so it launched Terminal. You closed the window, but did not quit from Terminal, so the Terminal icon is still in your Dock. Chances are when you quit Terminal it will disappear from your Dock.
If it is actually on the Dock while not running, then drag it off the Dock and when it goes "Poof", it will be gone from the Dock.