Here's a fiddle with a working example: http://jsfiddle.net/uBaZ6/1/
_.templateSettings = {interpolate : /\{\{(.+?)\}\}/g,
evaluate : /\{%([\s\S]+?)%\}/g,
escape : /\{%-([\s\S]+?)%\}/g};
var data = [{"username":"blue", "user_id":"1", "group_id":"1"},{"username":"teal", "user_id":"2", "group_id":"2"},{"username":"red", "user_id":"3", "group_id":"2"},{"username":"blue", "user_id":"1", "group_id":"1"}];
var dataSorted = _(data).chain().groupBy("user_id").sortBy("group_id").value();
var userTemplate = _.template($("script.template-users").html());
$("#acc").html(userTemplate({'groups':dataSorted}));
The key thing is that you need a named key for the template to get something to hold onto. Otherwise, it takes your array and just fills it into the global namespace, which in this case doesn't make sense because it's an array. So to fix that, just convert it into an object before you send it into your template. So for our first pass we map your data to groups
userTemplate({'groups':dataSorted})
and then we use it in the template like
{% _.each(groups, function(group){ %}
<h3>{%- group[0].group_id %}</h3>
You can see http://underscorejs.org/#template for more about Underscore templates. I think the developers don't really look at the US Templates as being very robust (or at least that's the way it used to be)