It is a bamboo peg (sometimes 2 pegs) that goes through the handle to keep the whole thing together. You can cut a piece of a chop stick and lightly wedge it in there as a temporary holder, but don't hammer it in tightly. Don't swing the sword, it's not safe. It must be reattached by someone who knows what they are doing. It will probably take someone who knows swords to examine it and give you info on it. Post pics and we can tell you something about it. There are many copies, some are very good, most are not.
Since you described how it came apart, and assuming the writting under the handle looks like it does in the photo above, chances are it's a real japanese sword. There are 2 distinct classes of japanese swords; 1) "Gunto" - Made from modern (homogenous) steel for the Military and 2) "Nihonto"- Traditional hand forged blades, which may be mounted in either traditional or military mounts. The second is usually far more valuable. Value depends on current condition and original quality. There are huge differences in the quality for both and current condition can destroy their value. Some things can be repaired or repolished up, but expert polishing is very expensive and usually only done to the finest blades. Otherwise it's not worth it.
Again, do not do anything to the blade or mounts. Do not clean or sharpen anything until you find out what they are. Sometimes an otherwise cheap sword with a ruined blade may have a single falmily heirloom, historic or valuable piece of accessory that can be worth thousands of dollars even without the blade. Like the handguard, dragon insets, etc. Each piece should be evaluated by an expert.
The only thing you can do is buy a bottle of food grade mineral oil from your local pharmacy. It is sold as a laxative. Not from the hardware store. You can lightly oil the blade with that and a clean soft cotton cloth. Do not handle with bare hands or scrub the blade.