(covers information from several alternate timelines)
The position of acting captain was bestowed upon an officer or another individual aboard a starship when the ship's regular commanding officer was unable to command for an extended period of time. This person is usually the first officer, and then continues down the ranks until someone is both physically and psychologically able to command.
While under the influence of the polywater intoxication, Wesley Crusher deemed himself "acting captain" of the USS Enterprise-D in 2364 after commandeering the ship from engineering. (TNG: "The Naked Now")
Lieutenant Commander Data became acting captain of the Enterprise in 2367 when Captain Picard was incapacitated due to a lack of REM sleep. (TNG: "Night Terrors") Three years later, Data again became acting captain when both Captain Picard and Commander Riker were held captive by Arctus Baran. (TNG: "Gambit, Part I", "Gambit, Part II")
Aboard the Silver Blood USS Voyager, its copy of Ensign Harry Kim assumed command of the starship as the highest ranking surviving officer, after his own senior officers had dissolved. (VOY: "Course: Oblivion")
In an alternate reality, Captain Pike of the USS Enterprise appointed Commander Spock acting captain and Lieutenant Kirk first officer when Pike left the ship to confront Nero. Subsequently, Kirk proved that Spock was unable to perform his duties and then Kirk himself was made acting captain. After everything was over, Kirk was promoted to the rank of captain and made the actual captain of the ship. (Star Trek)