You can keg before the end of fermentation but the reason to keg after terminal gravity is so you can control the amount of CO2 that is dissolved into your beer. If you keg prior to terminal, the yeast are still producing CO2 and the amount would be based on current gravity at the time you seal it in the keg and what you believe terminal gravity will be and then guess based on that. It is much easier to wait until fermentation has ceased. This means you can lager in keg without a problem. You can even combine lagering with carbonation or just go straight to the carbonation phase.
There are two ways to carbonate, conditioning, which is adding a specific amount of sugar into your fully fermented beer. Sealing up the keg and letting it sit in a warm space for 10 to 14 days. The remaining yeast will convert the sugar to CO2 and alcohol both of which will dissolve into the beer. Head space is a factor with this method so keep that in mind.
The other is forced carbonation where your beer is carbonated the same way as seltzer water. Place the beer under a specific pressure of CO2 from an outside source. That pressure is based on the beer's temperature and the volume of CO2 desired using the carbonation chart. Over time the gas dissolves into the beer. The time this takes depends on how the CO2 is introduced to the liquid. If you are just attaching a line to the gas in on a corney keg it can take weeks to dissolve the desired volume of CO2. This is because the gas and beer can only interact at the surface. This is why people shake their kegs in an attempt to increase the surface area and gas/liquid interaction. This has never produced the desired level of carbonation for me. I have a suspicion that a lot of gas is being wasted in generating foam instead of actually entering into solution, which is the ultimate goal. The most reliable way, I have found, is by using a 0.5 micron carbonation stone and a head pressure gauge. I've covered the process elsewhere on this forum but I get to my target volume in about 24 hours at 34ºF.
Serving your beer from keg is the same no matter which way you choose to carbonate. Your service pressure is based on the same temperature and pressure chart you would used to force carbonate. Find the volume of CO2 you choose for your beer. Check that against the temperature of your beer and then see what pressure the chart states. Take that pressure and run it through one of the beer line calculators you can find online. Then cut the line to that length. Assuming your measurements were correct and your lines are kept at the same temperature as the keg, you should get great pours of your beer from first to last.