So there are two endings one of manga and other is of anime
Firstly lets discuss about the anime ending
In the Anime, Yagami Light, Near, Matsuda and all the squad are in a sort of warehouse. When Light tries to get the piece of paper of his Death Note from the watch, he gets shot by Matsuda in non-fatal points, both times. While the other guy kills himself, Light runs away, and ends up in another building of what looks like an industrial area. Ryuk is on top of a chimney and speaking to himself, he “reminds” Light about his first promise, i.e. that he would be the one to write Light’s name on the Death Note. And that’s what he does.
in the Manga, Light is still in the warehouse and he sees Ryuk (Near sees him too since he has the Note as well) and he begs the Shinigami to write their names. Ryuk says “Ok Light, I’ll write…” and while everybody tries to shoot him, he adds “…your name, Light.” Light doens’t want to believe it but when Ryuk shows the Note, his name is written there. Light sees his entire life and remembers the same sentence Ryuk told him when they met (i.e. that he would be the one to write Light’s name on the Death Note). Ryuk adds “it would be hard to see you in prison and your life is over anyways” or something similar. After 40 seconds, Light dies in front of the two detective teams.