It took the composer William Bolcom over 40 years to follow his first piano concerto with a second one.

When Bolcom was putting the finishing touches on that first concerto, in 1976, he had already gained fame as part of the era’s ragtime revival. A pianist as well, he interpreted pieces by Scott Joplin and other originators, while also contributing to a new wave of writing for the form, on albums like “Heliotrope Bouquet.”

Milestones came after the concerto’s premiere. Bolcom’s prismatic “Twelve New Etudes for Piano” — which contained a crucial dollop of ragging energy — won the Pulitzer Prize for music in 1988. That decade, his expansive and amazing setting of William Blake’s “Songs of Innocence and of Experience” was a polyglot Achievement, full of music that might take stylistic succor from reggae or Tin Pan Alley, from one minute to the next.

Even as symphonies and other works for soloist and orchestra kept coming from the Bolcom workshop, no new piano concerto followed — a peculiar development, given his own stature as a keyboardist. But this April, that streak came to a close when Igor Levit and the Mahler Chamber Orchestra gave the world premiere performance of Bolcom’s Piano Concerto No. 2.

Don’t bother asking whether the premiere took place in the United States, where major presentations of music by Bolcom, an American, have fallen out of fashion. Instead, this new concerto was presented in Germany, at the Heidelberg Spring Festival. That organization, which commissioned Bolcom’s new concerto with Levit in mind, thankfully also documented the performance. And recently, it posted the video on YouTube.

In a phone interview, Levit described Bolcom as one of “the very essential composers of our time,” and also recounted with delight the way in which this composer, now 84, participated in the rehearsal process: by video conference, from his home in Ann Arbor, Mich. “You can tell that this piece, and writing music — any music — really means the world to him,” Levit said. “He was, in the most beautiful way, childishly happy.”

Bolcom, in a joint interview from his home with Joan Morris — his wife and collaborator, who finished some sentences and added cabaret-style jokes — recalled seeing, and enjoying, Levit’s performance of Beethoven’s Piano Concerto No. 4 at the Gilmore Piano Festival, in Kalamazoo, Mich., in 2018.

“I said,” Bolcom added, “’Now this is a guy I could write for.’”(He also called the Beethoven “probably my favorite concerto.”)

“I’m interested in a dialogue,” he said, describing his ideal relationship between a pianist and an orchestra, “like in a Mozart concerto, in which nobody is expecting the other person to try to win over the other.”

Bolcom’s second piano concerto, at a running time of 24 minutes, reflects that balance while synthesizing various musical traditions. In the early going, some tender yet mystic motifs suggest the songful chromaticism of Olivier Messiaen. But before long, in a transition that few composers could handle so successfully, stark pianistic marching leads the orchestra into the punchy environments of percussive Americana.

In an accompanying documentary that the festival produced and posted online, Levit says that Bolcom described the concerto to him as “a gentle piece for non-gentle times.” There is a hint, there, of Bolcom’s proclivity for political commentary. He described the finale of his Trio for Horn, Violin and Piano, from 2017, as a “resolute march of resistance” in response to the 2016 presidential election. And as far back as that first piano concerto, written during the post-Watergate bicentennial of American independence, Bolcom wrote that it was one of “one of the bitterest pieces” he’d conceived so far.

But such steady disillusionment has not staggered Bolcom’s imagination. Whereas his first concerto ends in a parade of riotous, Ives-like quotations — a cynical pileup of putatively patriotic melodic sentiments — the second is less obvious in its moods. Its melancholy, though impossible to miss, is also left by some ebullient twists, all of which are well served by Levit and the Mahler Chamber Orchestra, conducted by Elim Chan.

This blend of delight and an almost pained, Romantic yearning likewise comes to the fore in another recent recording of Bolcom’s music — by the pianist Marc-André Hamelin, who first recorded “Twelve New Etudes” and has also released an album with the first piano concerto.

Hamelin’s new recording, “Bolcom: The Complete Rags,” is — truth in titling! — the only survey of this catalog that manages to sweep up a few stray syncopated pieces the composer has ventured this century. If it lacks just a touch of the rambunctious energy that Bolcom himself brought to rags like “Seabiscuits Rag,” as heard toward the end of “Heliotrope Bouquet,” Hamelin’s interpretations are a marvelous, moving account of this lushly complex music.

Bolcom’s ability to move between poles of emotion, in his rags and concertos, is part of the great charm of his music. When I asked him about the surprising appearance of an electric keyboard part in his Symphony No. 3, I described it as sometimes sounding like a parody of midcentury American modernism and at other points as reminiscent of fusion-era Miles Davis. He let out a belly laugh.

“First of all: What’s not interesting to me is to make it all completely explicable,” he said. “It’s not explicable to me. I mean, I fly by the seat of my pants, musically.” And although he declined to be pinned down on any point of musical reference, he did admit, “Since the beginning, I’ve had love for the theater.”

That’s evident not only in his comic operas, such as “Lucrezia,” but also in the wild transitions embedded within his instrumental works. The new piano concerto, too, manages to surprise even as it is not interested merely in shock value.

For Levit, the concerto has “a great mastery of writing and level of seriousness and dedication to every little detail.” But for all that refinement, Levit said, it also shares a key trait with music of American artists like Esperanza Spalding, Fred Hersch and Frederic Rzewski — all of whom Levit cited as carrying a form of the colloquial spirit that is also present in Bolcom’s music .

“They never lost the connection to the people who would listen to the music,” Levit said. “This wire to the audience, the wire to the dimension in the hall, is really something which I find deeply inspiring.”