I would first like to say that I am not a pilot and all of my knowledge on this topic comes from watching youtube videos of ATC conversations.
If something happens on takeoff, the pilots will generally contact ATC pretty quickly and will say what happened and what their immediate intentions are. It’s also possible that they did not notice whatever incident happened, and maybe someone in the airport tower saw something or someone on another plane saw something. In any event, they generally either return to the airport or divert to a nearby airport.
They have a couple of choices. They can declare an emergency, or they can choose not to. It depends on how serious the problem is. You would think that losing an engine would always be an emergency, but I just watched a video last night where the pilot did not declare an emergency for a lost engine. It was a 747, which is designed to take off on 3 engines, fly on 2, and can land with just 1 engine working, and the plane wasn’t heavily loaded, so I guess the pilot was like eh, whatever, I lost an engine, I’m diverting to your airport, but it’s not an emergency. ATC still gave the plane priority. ATC did verify with the pilot twice that he wasn’t declaring an emergency, so I guess they thought that was a little odd.
They can also declare a pan-pan, which is saying that you have a problem but that it’s not an emergency (i.e. there’s no immediate danger to anyone’s life). An example of this was a small plane that had a pilot who was training and an instructor. The plane developed a problem with its elevator in that it got stuck somewhat and could only deflect so far upward. The instructor took control of the plane and declared a pan-pan and they went back to the airport. The instructor felt that he still had enough elevator control that it wasn’t an emergency.
If there is an emergency, the plane may have to dump fuel, or it may have to land with an overweight condition.
Generally, even though the pilots are dealing with something, they generally can follow ATC directions like level off there, turn to a particular heading, or whatever. If the pilots can’t comply, they will usually immediately say so (negative, we’ll be in the Hudson…). The pilots may request a lower altitude, or they may request a turn in a particular direction, if it is a two-engine plane and one of the engines has gone out for example. ATC is generally very helpful and will route other traffic away from the emergency aircraft, and will often ask the pilots what runway they would like to land on.
ATC will also put them into a holding pattern somewhere if the pilots request that, so that they can run some checklists or dump fuel. I’ve seen videos where the pilots have just requested a longer than usual return path to the airport so that they have a little extra time to run a couple of checklists.
For an emergency, ATC will also ask for fuel remaining and souls on board, and emergency services will also want to know if there are any hazardous materials on board. ATC usually says “when able” (or something similar) when asking this question. In other words, fly the plane first, answer ATC questions second.
ATC may roll out emergency vehicles even if it’s not an emergency and the pilot does not request it.
Once the plane lands, the runway will usually be closed immediately, and a safety car will inspect the runway to make sure there’s no problem, like no bits of the aircraft fell off and are now in the middle of the runway.
They will often close the runway and do an inspection if there was some sort of problem on takeoff as well, whether it’s a tail strike or a blown engine or a tire blowout or whatever. I’ve seen a couple of videos where the pilots said that they had some sort of indication on their engine but had no idea what the problem was, then ATC calls them back a couple of minutes later and tells them that they found a dead bird on the runway, so obviously the plane sucked a bird into its engine.