From left: Collaborators Questlove and Costello

The unexpected pairing of ELVIS COSTELLO and THE ROOTS leads to one of the most ambitious — and infectious — albums of the year.

As the house band for Late Night with Jimmy Fallon, The Roots are accustomed to blind-date collaborations with the talk show’s nightly musical guests. But the hip-hop group felt a special attraction to repeat guest Elvis Costello. After the British songwriter’s third televised performance with the band, drummer and band leader Ahmir “Questlove” Thompson worked up the nerve to pop the question.

“It’s like when you go out on three dates with a girl and she asks, ‘What are we? Shall we get married?’ We said, ‘Let’s record a song,’ ” Questlove recalls. “And then we did another one, and another one. Then, in January, we realized we had an album.”

The surprise collaboration, Wise Up Ghost (Blue Note, $15), melds ska, soul, hip-hop and horn-driven funk with Costello’s strongest melodies in years. “It’s sonically very different than anything I’ve done,” Costello says.

That’s saying something, given that Costello’s career boasts more unpredictable moves than a Garry Kasparov chess match. Originally a New Wave artist, he has also recorded country music with T Bone Burnett, orchestral pop with Burt Bacharach, jazz with Bill Frisell and a classical record with the Brodsky Quartet.

When Costello and Questlove began writing songs, they discovered they had much more in common than the Buddy Holly–­style glasses they each wear. “I wanted­ to ask him about 1977, because that was such an important year — that was when rap started,” Questlove says. Costello, in turn, marveled at a YouTube video of Questlove’s library of more than 70,000 records.

“He’s a very formidable drummer who also has a musical curiosity. Rhythm coming off the drums and rhythm coming off the words had a lot to do with how the melodies were shaped,” says Costello, who adopted an undulating vocal flow in response to ­Questlove’s coil-spring break beats. “It’s about having the ear for where the musical comma is in the phrase.”

For his part, Questlove was moved by the tenderness Costello brought to lush ballads “Tripwire” and “If I Could Believe.” “We had an epiphany when we were mixing the album to add strings to it,” he remembers. “Now it’s gone to a whole new level.”

Long after the initial musical courtship, Costello remains smitten. “The guys have a great way of putting their signature on these songs,” he says. “We wouldn’t be putting it out if we didn’t like it.”