Remember Matsuda's theory from 108? The one in which Near killed Mikami? The one that was pretty much obviously true? I'd like to expand upon it.
Light behavior in the last minutes of his life was strange, to say the least. Most importantly, his plan was idiotic and out of character. Seriously...compare his L plan (Lose his memory, capture a third Kira, prove his innocence, then get both L and a shinigami killed...extremely impressive) to his Near plan (Mikami looks through a fucking door). Either Light's IQ was halved, or something odd was at work. Then there was his mental breakdown...which makes some sense, but is still suspicious. Finally, his sad attempt to kill Near using the concealed scrap of the Death Note? That was completely un-Light. He knew that plan wouldn't work. Why would he do that?
Simple: He was being manipulated. Near wrote his name in the Death Note alongside Mikami's. He specified that Light would come to the warehouse on the assigned date, attempt to kill the people there, fail, have a breakdown, confess to being Kira, and die pathetically...or something of that sort. He might even have thrown the attempting to kill Near thing in there, or that might have come out of the breakdown part.
It explains Light's actions perfectly. His plan was stupid because he was being controlled by the Note. Ryuk's apparent execution of him could have been specified as well, or it might not have been...regardless, since Near would have written this out first, Ryuk's writing of the name wouldn't have undone the original "writing". Perhaps Near even wrote, "Dies at the hands of someone in the warehouse".
It makes perfect sense, given Near's character. He was a little brat obsessed with winning, and willing to do anything to accomplish it. He wasn't a good person like L, even Ohba admits that.