Pictures are really needed to answer, but here is my best guess based on the limited information...
It sounds like this light fixture was in the middle of a daisy chain with other lights. One set of 3 wires is probably the electrical supply to the light you were working on, and the the other set of 3 wires probably carries the electricity to the next light fixture in the chain. If there is another light fixture controlled by the same switch as this one, that is probably what is going on.
To test this safely, go get an 'electrical test pen'. They are inexpensive. With the light switch on, hold the end of the pen near each wire. It should light up next to one of the black wires. Then with the switch off, it should not light up at all, on any wire.
Before making connections, turn off the breaker, and hold your electrical test pen next to each wire, with the switch on, and with it off. The pen should not light up at all, on any wire. If the light turns on there is still electricity there, don't go any further. Find the correct breaker, or call a professional.
My guess is that the red wire is neutral, black is hot, and green is ground. If so, then the two black wires should be connected together and combined with the hot wire from your light fixture (probably also black). The red wires together, and with the neutral wire from your light fixture (probably white). The green wires should connect to each other and also to your junction box. If your light fixture has a ground wire, which may be green or may be a bare wire, it should be connected to the junction box as well, so that the two grounds, the light's ground, and the box are all connected together.