My daughter did the same thing at 18 months. The most important thing is to be consistent with whatever bedtime routine you choose. For my daughter, we would read a book or two (her choice) in her bed after brushing her teeth. It didn't work like magic right away, but after a few weeks of doing the same things, she realized that it was time for bed and that she needed to stay in her room. She always had a little night light in her room, and a CD player with bedtime songs playing, and when she would come out, we'd put her back in and tell her that if she came out again, we were going to turn the songs off. Then if she came back out after turning the songs off, her night light would go off. (of course, it wasn't pitch black in her room, but she preferred the light on.) A few times, we would put the baby gate up so she couldn't get out, and once she climbed over it, we would put a second one up right on top of the first so it was too high. She didn't have to have that done very often, but when it was a particularly bad night for her staying in her room, that's what we did. Before we even started the whole bedtime routine each night, we'd set a timer and tell her that when the timer goes off, it was time for bed. Then we'd brush her teeth, say her prayers, read a book, and put the songs on. We also told her that if she wasn't tired enough to go to sleep, that she could read some books on her own. She had a chair in her room that she could put by the night light so she could read until she was tired. She usually would end up asleep in her bed within an hour.
My boys (22 month old twins), on the other hand, destroy just about anything left in their room with them at nap or bedtime. Books for them were out of the question. So we put two musical toys in their room (durable-destruction resistant) so if they weren't tired enough to go to sleep, they could play with those for a while. We also put music on for them. To keep them in their room, we put the door knob covers on so they can't open the door in the first place. Once the routine is established and your son gets used to sleeping in his big boy bed and learns that he needs to stay there all night, he'll probably do much better. The most important thing is to be consistent. If you let him sleep in your bed one night, and return him to his the next, he'll try over and over again until you cave. After two days, it's expected that he'll try to get out. After all, he hasn't had that freedom in the past. To teach him to stay there, put him back in bed each time he comes out, explain that it's time to stay in bed, and start putting the gate up, or some other deterrant that works each time he comes out after that first time during the night. Anyway. Sorry for the length. Hopefully something I suggested will help. Good luck!