We study online learning in episodic tabular Markov decision processes (MDPs) with adversarial losses and unknown transitions under bandit feedback. For this problem, the best known regret bounds are $\widetilde O(HS\sqrt{AT})$ and $\widetilde O(H^{5/2}\sqrt{SAT})$, where $H$ is the horizon, $S$ the number of states, $A$ the number of actions, and $T$ the number of episodes. However, these bounds do not match the lower bound $Ω(H\sqrt{SAT})$, and it has long been unknown whether this gap can be closed. We close this gap by giving the first algorithm that attains regret $\widetilde O(H\sqrt{SAT})$ with high probability, which matches the lower bound up to logarithmic factors. Our algorithm runs follow-the-regularized-leader (FTRL) over occupancy measures and avoids the two sources of the extra factor $\sqrt S$ in existing algorithms of this type. First, instead of bounding the mismatch between the estimated and true occupancy measures by the width of a confidence set of transitions, we estimate the loss due to this mismatch by temporal-difference errors and add the estimate to the loss that FTRL uses. As a result, a fixed bound on the relative error of the transition probability estimates suffices for the regret guarantee. Second, instead of dividing each observed loss by an upper occupancy bound over a confidence set, we deliver the loss to FTRL gradually over later episodes, refining geometric resampling with rejection.