When my grandmother died, a really close friend said "but at least this is the grandmother you aren't close to". Don't do that, ever, and instead read Fixing Shiva by Rabbi Eliyahu Fink. His advice isn't at all limited to people observing the Jewish tradition of shiva and essentially boils down to give hugs:
It is not your chance to play armchair therapist to fix the mourner or amateur journalist to elicit all the facts and figures surrounding the death. Provide unbridled love and support. Be a listener. Be empathetic. Be what they need you to be.
Don't try to fix things
Mourning is not the time for all sorts of invasive questions about what the deceased suffered from or what the medical treatment was. And don't start in with the stories and analogies and "this is what God/the universe/fate wanted"-the mourner already knows this and either it already makes em feel better or it doesn't-hearing it from you though? Nah, not gonna make a difference.
Be liberal with hugs
Both literal and figurative. If you're close and you know the person appreciates real hugs, do that. If they don't do hugs, offer to bake food or watch small children or do some other nice little thing that shows you care. Share (nice, funny, good) stories about the person who died, or about the mourner telling you stories about the person who died. Basically, just be all warm and fuzzy and unconditionally loving.
Everyone is different, but the thing that comforted me a ton when my grandmother died? Condolence texts. A professor who lost her husband said that the condolence cards meant a lot to her too. Just knowing that someone else recognized my sadness as valid and was sad that I was sad was a huge virtual *hug* and meant all the world to me. Your mourner may vary, and part of being there for them is reaching out and listening to what they want. Just go and give all the love.
Be around, or at least present
ETA: collierLA (who also came up with the headline) makes the great point that you should be present and keep in touch. Let the person know that you're there if they need you, and ping 'em by voicemail, text, or email every once in a while (weekly, in a month, etc) to show 'em that you still love 'em. Offer to take 'em out for coffee or come over for tea. As Collier says:
I think the most helpful thing is to just be around. go out for coffee, go shopping, go to dinner. like it's Normal. don't bring it up. and if THEY bring it up, don't panic because you're expected to Fix It. you're not.
She points out that being specific about plans is good:
don't feel leery about making plans or asking to get together. ASK. Hey, want to do dinner Friday? Because the bereaved is acutely aware (often wrongly) that they represent An Emotional Burden now. So if you ask "do you want to maybe do something sometime? are you okay?" the answer will invariably be "no, that's okay, I'm fine."
Being specific is also good because people often don't know what they can ask of you or what you're willing to offer. So "hey, would you like a plate of cookies" is more helpful than "hey, can I bring something?"
Just remember that it's all about the mourner and showing them that you love 'em.